Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
const animal = { breathe() { return this.name + ' breathes'; } }; const dog = Object.create(animal); dog.name = 'Rex'; dog.bark = function() { return 'Woof!'; }; console.log(dog.bark()); // Woof! console.log(dog.breathe()); // Rex breathes (inherited) console.log(dog.hasOwnProperty('bark')); // true console.log(dog.hasOwnProperty('breathe')); // false console.log('breathe' in dog); // true console.log(Object.getPrototypeOf(dog) === animal); // true
Result
Open