<script type= "Text/javascript" >
function person (name, age) {
This._name = name;
This._age = age;
var _self = this;
This.say = function () {
Console.log (This._name + '-' + this._age);
SetTimeout (function () {
Console.log (_self._name);
}, 2000);
}
}
Person.prototype.foot = function () {
Console.log ("I foot" + this._age);
}
var xiaoming = new Person (' xiaoming ', 18);
Xiaoming.foot ();
Console.log (Json.stringify (xiaoming));
</script>
The meaning of prototype in the software world is the original form of the Table object. The prototype in JavaScript.
All objects of the function type of JS have a prototype property. This prototype property itself is an object type, so you can add arbitrary properties and methods to the prototype object.
Inside JavaScript, the object's properties and method traceability mechanisms are implemented through the so-called prototype chain. When an object is constructed with the new operator, the prototype object of the constructor is also assigned to the newly created object as a prototype object built into the object. The prototype object built into the object should be invisible to the outside, although some browsers (such as Firefox) can let us access this built-in prototype object, but it is not recommended.
This is the "inheritance"of JavaScript!
With inheritance we can extend the existing objects (including JS built-in objects, custom objects) conveniently!
Prototype extension of JavaScript objects (JS object-oriented inheritance)