1. to prototype a parent object as a new object
function Object (o) {var n;function f () {}f.prototype = O;n = new F (); n.uber = O;return n;} var shape = {name: ' Shape ', tostring:function () {if (This.uber) return this.uber.toString () + ', ' + this.name;elsereturn thi S.name;}} var Twodshape = object (Shape), Twodshape.name = "2 D shape"; alert (twodshape.tostring ());
2. Call the parent constructor parent.apply () in the sub-constructor and pass the arguments so that the property of the this bound to the parent object becomes the child object at the same time
function Shape (id) {this.id = ID;} Shape.prototype.name = ' shape '; Shape.prototype.toString = function () {return this.name;}; function Triangle () {shape.apply (this, arguments);//native Property inheritance}
JavaScript Object-Oriented programming (11) Other ways to inherit