Last active
May 14, 2018 21:00
-
-
Save etoxin/afcd1c7938e24f07d92833f08bf02e5c to your computer and use it in GitHub Desktop.
Sharing between Objects
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 Vehicle = { | |
describe: function () { | |
return `This ${this.type} is the ${this.make} ${this.model}.`; | |
} | |
} | |
var Car = Object.create(Vehicle, { | |
type: {value: 'Car', writable: true} | |
}); | |
var Holden = Object.create(Car, { | |
make: {value: 'Holden', writable: true} | |
}); | |
var Commodore = Object.create(Holden, { | |
model: {value: 'Commodore', writable: true} | |
}); | |
console.log(Commodore.describe()); | |
// "This Car is the Holden Commodore." |
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 Vehicle = { | |
describe: function () { | |
return `This ${this.type} is the ${this.make} ${this.model}.`; | |
} | |
} | |
var Car = { | |
__proto__: Vehicle, | |
type: 'Car', | |
} | |
var Holden = { | |
__proto__: Car, | |
make: 'Holden', | |
} | |
var Commodore = { | |
__proto__: Holden, | |
model: 'Commodore', | |
} | |
console.log(Commodore.describe()); | |
// "This Car is the Holden Commodore." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment