javascript 继承
function inheritPrototype(subType, superType){var prototype = object(superType.prototype); //create objectprototype.constructor = subType; //augment objectsubType.prototype = prototype; //assign object}function object(o){function F(){}F.prototype = o;return new F();}
function SuperType(name){this.name = name;this.colors = [“red”, “blue”, “green”];}SuperType.prototype.sayName = function(){alert(this.name);};function SubType(name, age){SuperType.call(this, name);this.age = age;}inheritPrototype(SubType, SuperType);SubType.prototype.sayAge = function(){alert(this.age);};
页:
[1]