In an example from Node.js Design patterns
function createProxy(subject) {
var proto = Object.getPrototypeOf(subject);
function Proxy(subject) {
this.subject = subject;
}
Proxy.prototype = Object.create(proto);
//proxied method
Proxy.prototype.hello = function() {
return this.subject.hello() + ' world!';
}
//delegated method
Proxy.prototype.goodbye = function() {
return this.subject.goodbye
.apply(this.subject, arguments);
}
return new Proxy(subject);
}
What is the need for the method delegation i.e. to redefine the Proxy.prototype.goodbye method again when the method from original Object will be automatically be called as the prototype chain has been set i.e. Proxy.prototype = Object.create(proto). Thanks in advance.