What are the principles of javascript prototype object this
In this article, the editor introduces in detail "what are the principles of javascript prototype object this", the content is detailed, the steps are clear, and the details are handled properly. I hope this article "what are the principles of javascript prototype object this" can help you solve your doubts.
Principle
1. Only when this function is called can you determine who the this in the constructor points to.
2. Generally speaking, the this in the constructor refers to the caller of the function.
Example
Function Star (uname, age) {this.uname = uname; this.age = age;} var that; Star.prototype.sing = function () {console.log ('I can sing'); that = this;} var ldh = new Star ('Andy Lau', 18); / / 1. In the constructor, this points to the object instance ldh ldh.sing (); console.log (that = ldh); / / 2. The this in the prototype object function points to the instance object ldh. Here, the article "what are the principles of javascript prototype object this" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it before you can understand it. If you want to know more about related articles, please follow the industry information channel.