A, the prototype of this thing, when we interview always will be asked, sometimes is really not good answer, now I will briefly summarize the JS prototype! It’s not too awkward to say a little when asked later in the interview.
function yuanxing(){
console.log("What is a prototype?")}Copy the code
This function is also an object. Then all function objects have a prototype property, which is the prototype object of the function. When we create a new instance, that instance will have a __proto__ property, which is the prototype property of the browser, some browsers support it, some don’t. The prototype of the instance is the prototype of the function object, then the prototype is the prototype of the object, and then the prototype of the object is Null. Which brings us to the question of prototype chains. When we look to see if an object has a certain attribute, we will first look for itself. If it does not, we will look for its prototype and find an attribute step by step. When we find Null, we have found the end of the prototype chain. Check out the picture below!You look at the picture and then look at the text will slowly understand the prototype and prototype chain these two things, so JS prototype, we generally used for what? Do we use it on a regular basis? This I will not say, because we usually really use less, if you want to know how to use it, you can go to see some framework source code, which is more helpful to understand this thing! This issue is over here, you learn to waste it!!