Proxy in prototype chain

node v10.24.1
version: 1.0.0
endpointsharetweet
function Person(first, last, age) { this.first = first; this.last = last; this.age = age; } Person.prototype.greeting = function () { return `Hello my name is ${this.first} and I am ${this.age} years old`; }; let validator = { set: function(target, key, value, receiver) { console.log(`The property ${key} has been updated with ${value}`); target[key] = value; console.log(receiver.first); return true; } }; Person.prototype = new Proxy(Person.prototype, validator); let george = new Person('George', 'Clooney', 55) Person.prototype.farewell = function () { return `Hello my name is ${this.first} and I will see you later`; }; george.foo = 'bar' Person.prototype
Loading…

no comments

    sign in to comment