1. Prototype is a property of a class, in other words, a static property
2. Ptototype and __proto__, the former is the property of the class, the latter is the object property
3. Examples of prototype and __proto__
<script>
function person () {
This.age = 22;
This.sex = "Man";
}
Person.prototype.showInfo = function () {
Return "It is first time-to-public-what I learning!" + "Person Object-is" + This.age + ", sex is" + this.sex;
}
var p = new person ();
P.age = 23;
P.sex = "also man";
P.__proto__.showmsg = function () {
Return "My name is Askmewhy.i ' m" +this.age + "years old and I ' m" + this.sex;
}
document.write (New Person ()). Showinfo ());
document.write ("<br>");
document.write (P.showmsg ());
</script>
It is also important to note that when you look at it, you always think that the prototype reference is to the parent class, so it is assumed that Person.prototype is adding properties to the parent class object. There are two ways to detect whether an object or class contains a specified property:
<script>//var p = new person (); At first I thought it was true or false.document.write (P.hasownproperty ("Showinfo"));//true (Error) correct answer: false
document.write ("<br>");
Initialize an existing property
Document.wriete (P.hasownproperty ("Age")); True
document.write ("<br>"); //var o = new Object ();document.write (O.hasownproperty ("Showinfo"));//False
document.write ("<br>"); //Classdocument.write (Object.hasownproperty ("Showinfo"));//false
Summary: The method cannot check whether the object's prototype chain contains an attribute, and the property must be a member defined by the object itself
</script>
The above methods are tested in IE-11.
So if we were to detect if an object in the prototype chain contained a specified property, I would have left the enumerable properties of the object to traverse.
<script> //person Object Properties for var in p) { + " <br> "); } // object property for (var in o) { + "<br>"); } </script>
The above is my judgment, confirming that the Showinfo attribute exists in the Person class property, and that the parent class does not have the custom attribute.
The above is my first blog, if there are any shortcomings, please kindly point out and pointing twos, common progress.
I am a rookie, I speak for myself!
The prototype of javascript-learning note-taking record