We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hiya,
This isn't technically a 'using p5' question, but I'm getting into writing my own client side js libraries and I wanted to see how p5 used both static and instance versions of functions such as p5.Vector.sub() ... so take a look here:
https://github.com/processing/p5.js/blob/master/src/math/p5.Vector.js#L269
I'm guessing lines 282-284 are the static version, but why does the function reference the x, y, z that belong to 'this' before returning it ? Aren't those instance variables ? It also performs -= on them, so surely if you use the static version more than once, won't it be affected by all the previous times you used it ?
Many thanks for any pointers.
Thx, Loz
Answers
https://GitHub.com/processing/p5.js/blob/master/src/math/p5.Vector.js#L269-L286
https://GitHub.com/processing/p5.js/blob/master/src/math/p5.Vector.js#L1080-L1088
If you wish, you may also take a look at Pjs' own implementation of class PVector:
https://Gist.GitHub.com/GoToLoop/acbf106aa784820aff23
It's much closer to Processing Java's PVector class than p5.js is. ~O)
as usual, you nailed it matey :):)
totally missed that it has functions both on and not on the prototype.
thx !