I was wondering why the Vector variable defined within this self executing javascript function doesn't require a var before it? Is this just some other type of syntax for creating a named function? Does this make it so we can't pass Vector as an argument to other functions?
(function() {
Vector = function(x, y) {
this.x = x;
this.y = y;
return this;
};
//...snip
})()
The code construct above makes Vector a global variable in the namespace, which might be OK since it is probably intended to be used as constructor.
I would not recommend adding to the global name space, actually take a look at requirejs its a very nice way to work with modular JS.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With