Talk:JavaScript/Notes/Function

From Noisebridge
Revision as of 20:10, 8 December 2013 by Johnyradio (talk | contribs)
Jump to navigation Jump to search

Uppercase function name indicates a constructor (just a convention, not interpreted). Every function is an instance of the Object function. Object has .prototype property, therefor every function has


Internal prototype and protoype property are not the same thing. Prototype is a property of obj

All Functions have a Call. All User-Defined Functions have a Construct. Class automatically becomes reference to Object on new instance of UD Fx.

Reference: Something is a something of the variable environment.

All about why [this] would be undefined.

Call is internal, automatically invoked, not explicitly called. s.move invokes Call internally.

When evoked within the context of an [this] will All instances of an o

Every function has Function.prototype for it's internal prototype property.

Calling a property (eg .move) of an instance of an object (eg Slider) will first look in the Constructor for that property, which is actually getting to the property through the instance's prototype property. If not found, the call looks for the property definition (of .move) in a separate definition of that property (eg. Slider.prototype.move =...) , which internally is getting the definition from the global prototype property of Object.

You can redefine a function name to some other function or value later in the program.

When you create a new instance of a function, the

function Slider(dir) {

 this.dir = dir;

} Slider.prototype.move = function(d) {

 alert(this.dir + ", " + d);

};

var d = new Slider("h").move; d (1); // Explain the result.

var s = new Slider("h"); s.move(1)

// equivalent to s.move(1) d.call(s, 1);

// say you want to convert a nodelist into an array, in order to get array sort and other list-management functions. You can use the slice function of Array using call: var nodelist = document.getelementsbytagname("*"); //or document.body.descendents?; var NodeArray = Array.prototype.slice.call(nodelist);

// slice converts the elements into an array of elementNodes (which is defined in the DOM host environment).