- jQuery wraps it’s entire code base in:
(function( window, undefined ) {
})(window);
Is this used so you can define any functions inside there without littering up the global namespace?
Then explicitly expose parts you want with window.xxx = yyy; ?
What is the code precisely doing?
It looks as if you can pass any number of objects into it - I’m not sure what the (window) at the end is doing.
–
2. prototype keyword:
is the prototype keyword’s sole purpose to add functions to all instances of existing objects?
Car = function(make) {
this.make = make;
}
var honda = new Car('honda');
Car.prototype.numberOfWheels = 4;
alert(honda.numberOfWheels);
Can’t you just add all the properties to an object before you create instances of them? Why is it necessary to add this dynamically after initialisation?
3. multiple = assignments:
There’s code like this used throughout:
jQuery.fn = jQuery.prototype = {}
It seems pretty straight-forward but wanted to check I had understood correctly, all variables on the left of the last assignment get the lasts value.
var one = 1;
var two = 2;
var three = 3;
var x = one = two = three;
alert(one);
alert(two);
alert(three);
alert(x);
Thanks,