IK
Interview Knowledge Book
Topics
Practice
Examples
Playground
RU
browser
Prototype delegation lookup
Show that prototype methods are delegated and not copied onto each instance.
index.js
function User(name) { this.name = name; } User.prototype.speak = function speak() { return `${this.name} says hi`; }; const ada = new User('Ada'); console.log(ada.speak()); console.log('own speak', Object.hasOwn(ada, 'speak')); console.log('prototype speak', Object.hasOwn(User.prototype, 'speak'));
Run
Stop
Reset