-
-
Save nebiros/3ff8edd4fb41d5df4483 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// función constructora intermediaria | |
function inherits(Child, Parent) { | |
function I(){} | |
I.prototype = Parent.prototype; | |
Child.prototype = new I(); | |
Child.prototype.constructor = Child; | |
Child.prototype.__super__ = Parent; | |
} | |
function Hi(msg) { | |
this.msg = msg; | |
} | |
Hi.prototype = { | |
constructor: Hi, | |
say: function (msg) { | |
return this.msg + " " + msg; | |
} | |
} | |
function MyHi(msg) { | |
// llamamos al constructor de la class padre, 'Hi' a | |
// traves del atributo '__super__', este atributo es creado | |
// en nuestra función 'inherits' | |
this.__super__.call(this, msg); | |
} | |
// heredamos de la clase 'Hi' | |
inherits(MyHi, Hi); | |
var hi = new MyHi("mundo"); | |
console.log(hi.say("hola")); // mundo hola | |
console.log(hi instanceof Hi); // true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment