Prototype action on an object in JS, you can add properties and methods to an object.
Syntax: Object.prototype.name=value
Details: When an object is created through a class, the order in which the JS looks for properties is:
1. Properties of the object itself, such as obj={} obj.age=18
2. Find prototype in the class of the object, such as obj={} obj.prototype.age=18
3. Find in the object's root object (object)
4. After the class definition of an object, you can add a new property and method to the class of the object through prototype, after which the property or method is available through the newly created object of the class
function Persion () {
This.name= "Xiaol"
}
P1 = new Persion ()
P1.name//"Xiaol"
Persion.prototype.age = 18
P1.age//18
P2 = new Persion ()
P2.age//18
5. Obj.hasownproperty (attrname) to determine whether a property is an attribute of the object itself, such as Obj.hasownproperty ("age") returns false
6. Use Attrname in obj to determine whether a property is within an object (including its own and prototype properties), for example: "Age" in P1 returns ture
JS's Prototype property