June 2014
Intermediate to advanced
696 pages
38h 52m
English
An even more advanced method of creating objects is using a prototyping pattern. You implement a pattern by defining the functions inside the prototype attribute of the object instead of inside the object itself. With prototyping, the functions defined in the prototype are created only once, when the JavaScript is loaded, instead of each time a new object is created.
The following example shows the prototyping syntax:
function UserP(first, last){ this.first = first; this.last = last;}UserP.prototype = { getFullName: function(){ return this.first + " " + this.last; }};
Notice that you define the object UserP and then set UserP.prototype to include the getFullName() function. ...
Read now
Unlock full access