Maisara-WD Posted August 15, 2008 Share Posted August 15, 2008 Hipeace upon uIs the prototype property used to define a new property to an object,, tell me if I undestood well...I'm sorry for this silly questionthanxbye Link to comment Share on other sites More sharing options...
Ingolme Posted August 15, 2008 Share Posted August 15, 2008 prototype can add new properties and methods to a class. It has to do with Javascript's version of object-oriented programming. Link to comment Share on other sites More sharing options...
justsomeguy Posted August 15, 2008 Share Posted August 15, 2008 You can use prototype to add or change a class. The array class, for example, has a method called push that adds another element onto the end of the array. If you wanted to push an element and then alert the length of the array, you could make your own method: Array.prototype.push2 = function (val){ this.push(val); alert(this.length);} Then when you make an array object you can access that method like the built-in ones.var list = new Array;list.push("1");list.push2("2");A class prototype is basically a blueprint of how the class works, Javascript lets you change the prototypes for the built-in classes. Link to comment Share on other sites More sharing options...
jeffman Posted August 15, 2008 Share Posted August 15, 2008 The benefits to modifying a class of objects come when you need to declare multiple instances of that object. Then the new attribute or method already exists; it doesn't have to be added on to each instance. So if you modified the Array object according to JSG's example, *every* array in that script will have the push2 method available to it automatically. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.