JavaScript preventExtensions() method

The Javascript handler preventExtensions() method traps the Object.preventExtensions method. New properties can not be added to the object when extensions are prevented.

Syntax:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
preventExtensions: function(target)
preventExtensions: function(target)
preventExtensions: function(target)

Parameters:
target: It represents the target object.

Return:
Boolean.

Example:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!DOCTYPE html>
<html>
<body>
<script>
const handler = new Proxy({}, {
preventExtensions: function(a) {
Object.preventExtensions(a);
return !Object.isExtensible(a);
}});
document.writeln('Value: ');
document.writeln(Object.isExtensible(handler));
</script>
</body>
</html>
<!DOCTYPE html> <html> <body> <script> const handler = new Proxy({}, { preventExtensions: function(a) { Object.preventExtensions(a); return !Object.isExtensible(a); }}); document.writeln('Value: '); document.writeln(Object.isExtensible(handler)); </script> </body> </html>
<!DOCTYPE html>
<html>
<body>
<script>
const handler = new Proxy({}, {
preventExtensions: function(a) {
Object.preventExtensions(a);
return !Object.isExtensible(a);
}});
document.writeln('Value: ');
document.writeln(Object.isExtensible(handler));
</script>
</body>
</html>