-
-
Save pedrogk/5fce53de844cbc6f2ec13857d46fbd58 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var o = { | |
a: 2, | |
m: function(b){ | |
return this.a + 1; | |
} | |
}; | |
console.log(o.m()); // 3 | |
// 'this' se refiere a 'o' cuya propiedad 'a' vale 2, | |
// así que m() regresa 3. | |
var p = Object.create(o); | |
// 'p' es un objeto que hereda de 'o' | |
p.a = 12; // crea en 'p' la propiedad 'a' con valor 12 | |
console.log(p.m()); // 13 | |
// 'p' no define propiedad m() así que se aplica la del prototipo | |
// pero ahora 'this' se refiere a 'p' cuya propiedad 'a' vale 12, | |
// así que m() regresa 13. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment