This article is a mirror article of machine translation, please click here to jump to the original article.

View: 11758|Reply: 0

[JavaScript] js object method, class method, and prototype method are differentiated

[Copy link]
Posted on 6/13/2017 2:03:38 PM | | |

Prototype is a very important concept in Js, each function (in Js the function is also an object) has a property called prototype, that is, the prototype), but under normal circumstances, its value is null, but it has a very important function is that the instances will share its properties and methods (this is the basis for implementing inheritance in Js)!
Prototypes are shared for instances of objects, which is both convenient for the program and confusing, with many unexpected results!



[Quote]
1. The object method includes the method in the constructor and the method on the constructor prototype;
2. Class method, in fact, the class here is a function, in js because the function is also an object, so you can add attributes and methods to the function, this method is more used in node;
3. The prototype method is generally used for object instance sharing, such as Person.prototype.sayName=function(){console.log(this.name); }; Add the method to the prototype to enable sharing. This eliminates the need to allocate memory to an instance every time it is initialized.





Previous:5 debugging tips for JS debugging
Next:vs Develop copyright notes plugin [source code]
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com