Javascript: Наследование
23 июля 2016, 16:35
function extend(Child, Parent) { var F = function() { } F.prototype = Parent.prototype; Child.prototype = new F(); Child.prototype.constructor = Child; Child.superclass = Parent.prototype; } function Box(){ console.log("constructor"); } Box.prototype.show = function(){ console.log("show();"); }; function IconBox(){ //IconBox.superclass.constructor(); console.log("constructor IconBox"); }; //extend(IconBox,Box); //IconBox.prototype = Object.create(Box.prototype); IconBox.prototype = new Box(); var box = new IconBox(); box.show();
Твитнуть
Поделиться
Поделиться
Популярное
