Can I assign Proxy to Number.prototype somehow? I want to be able to call:
42..anyMethod
I just found the solution.
Object.setPrototypeOf(Number.prototype, new Proxy({}, {
get(target, prop, receiver) {
return prop in target || typeof prop === 'symbol' ? target[prop] : { target, prop, receiver };
}
}));
No, this is not possible. The builtin prototypes are locked down, Number.prototype
is not writable and even if it was then Number
would still ignore it and construct objects with the builtin prototype.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.