@@ -67,8 +67,7 @@ dan.age = 26;
67
67
console . log ( dan . age ) ; // 26
68
68
console . log ( james . age ) ; // undefined
69
69
70
- // También podemos crear estas propiedades directamente en el "constructor".
71
- // Podemos crear funciones por ejemplo:
70
+ // Genial, pues vamos a crear métodos, por ejemplo:
72
71
function Person ( name ) {
73
72
this . name = name ;
74
73
this . greet = function ( ) {
@@ -186,12 +185,15 @@ function Taxi() {
186
185
// Hacemos que Taxi "herede" de Automobile. Para ello creamos un prototipo para Taxi, gracias a
187
186
// Object.create que crea un nuevo objeto cuyo prototipo podemos hacer que apunte a donde queramos.
188
187
// Ademas hay que setear su constructor.
189
- Taxi . prototype = Object . create ( Automobile . prototype ) ; // Crea un objeto nuevo {__proto__: arg}
190
- Taxi . prototype . constructor = Taxi ;
188
+
189
+ Object . setPrototypeOf ( Taxi . prototype , Automobile . prototype ) ;
190
+
191
191
// Una forma equivalente sería directamente apuntando a donde queramos
192
+ // Taxi.prototype = Object.create(Automobile.prototype); // Crea un objeto nuevo {__proto__: arg}
193
+ // Taxi.prototype.constructor = Taxi;
194
+ // Incluso también podríamos hacerlo de la siguiente forma:
192
195
// Taxi.prototype.__proto__ = Automobile.prototype;
193
- // Otra forma más limpia sin sobreescribir esta propiedad __proto__ es:
194
- // Object.setPrototypeOf(Taxi.prototype, Automobile.prototype);
196
+ // Taxi.prototype.constructor = Taxi;
195
197
196
198
// Añadimos también algún método a Taxi.
197
199
Taxi . prototype . service = function ( ) {
0 commit comments