February 2018
Intermediate to advanced
298 pages
8h 22m
English
The preventExtensions trap is executed when we prevent the addition of new properties using the Object.preventExtensions() method. It takes only one parameter--that is, the target object.
It must return a Boolean, indicating whether it has successfully prevented the extension of the object or not.
Here is a code example that demonstrates how to use the preventExtensions trap:
const proxy = new Proxy({}, { preventExtensions(target) { Object.preventExtensions(target); return true; } }); Reflect.preventExtensions(proxy); proxy.a = 12; console.log(proxy.a); //Output "undefined"
Read now
Unlock full access