Skip to content

Instantly share code, notes, and snippets.

@wentout
Created September 7, 2020 09:23
Show Gist options
  • Select an option

  • Save wentout/8f17ae2c9280cdf577f2f1a5ae175467 to your computer and use it in GitHub Desktop.

Select an option

Save wentout/8f17ae2c9280cdf577f2f1a5ae175467 to your computer and use it in GitHub Desktop.
// Number -> Proxy Life Cycle
// Number -> Proxy Life Cycle
const ogp = Object.getPrototypeOf;
var a = new Number(5);
a.extract = function () {
return a.valueOf();
};
console.log(a.extract());
var b = new Proxy(a, {});
console.log(b.extract());
var c = new Number(7);
c.extract = function () {
return c.valueOf();
};
Object.setPrototypeOf(Object.getPrototypeOf(c), b);
console.log('c.valueOf()', c.valueOf());
console.log('c.extract()', c.extract());
console.log('ogp(c).extract()', ogp(c).extract());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment