bad wording.
function createperson(name,qq) {//Constructors /* The new constructor will automatically be the new Object object, var this = new object (); Finally, the new this object is returned, return this; */ This. name=name;//Property name This. qq=qq;//Properties QQ This. showname= function() {Alert (' My name is: '+ This. name); } This. showqq= function() {Alert (' My QQ number is: '+ This. QQ); }}varobj=NewCreateperson (' user1 ',' 1234 ');varObj2=NewCreateperson (' User2 ',' 5678 ') alert (Obj.showname = = Obj2.showname);//false/* The showname of the two new build objects are different for new objects, and memory consumption is affected by excessive performance. * /
good wording.
function createperson(name,qq) {//Constructors This. name=name;//Property name This. qq=qq;//Properties QQ}createperson.propotype.showname= function() {Alert (' My name is: '+ This. name);} createperson.propotype.showqq= function() {Alert (' My QQ number is: '+ This. QQ);}varobj=NewCreateperson (' user1 ',' 1234 ');varObj2=NewCreateperson (' User2 ',' 5678 ') alert (Obj.showname = = Obj2.showname);//true/ * At this point the two obj showname are the same * /
Object-Oriented Programming : Add attributes (variables) with constructors, and use prototypes to add methods (functions).
into the prototype, and put it in the constructor differently. Because name, QQ is indeterminate, and the method shown is the same.
Object- oriented : When working with objects, focus only on the functionality provided by the object, without paying attention to its internal details, such as jquery
CSS |
|
JavaScript |
Class |
Add to a group of elements at once |
Prototype |
Style |
Add to one element at a time |
A method to add to an object |
A prototype is equivalent to a class in CSS, adds to a set of elements, and can inherit a common
varnewArray();
class |
Object |
Mold |
Products (finished) |
Array () |
Arr |
Can be new Array () |
Do not use new arr () |
Array is a die, does not have the actual function, cannot array.push () |
ARR is a product that is brought to use and can be Arr.push () |
Classes have prototypes that can be Array.prototype |
Object has no prototype and cannot be Arr.prototype |
JavaScript Object-Oriented programming