-
-
Save nebiros/8ca4592a0487cebdf7ef 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
function Blah() { // función constructora, constructor o clase | |
this.value = 42; // atributo | |
} | |
Blah.prototype = { // atributo 'prototype' | |
constructor: Blah, // atributo 'constructor' | |
method: function() { // método | |
return "hiya!"; | |
} | |
}; | |
function Foo() {} // función constructora, constructor o clase | |
Foo.prototype = new Blah(); // heredamos del objeto 'Blah' asignando una instancia de este al atributo 'prototype' | |
Foo.prototype.constructor = Foo; // 'constructor' | |
// una instancia de Foo | |
var foo = new Foo(); | |
// el valor de nuestro atributo 'value' que heredamos de 'Blah' | |
console.log(foo.value); // 42 | |
// lo que retorna nuestro método 'method' que heredamos de 'Blah' | |
console.log(foo.method()); // hiya! | |
// instanceof | |
console.log(Foo.prototype instanceof Blah); // true | |
// uno de los métodos que heredamos de 'Object' | |
console.log(foo.toString()); // [object Object] | |
// el tipo de 'method' | |
console.log(typeof foo.method); // function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment