C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
JavaScript handler.preventExtensions() MethodThe handler.preventExtensions() method is used to trap the Object.preventExtensions method. When extensions are prevented on an object, new properties can't be added. SyntaxpreventExtensions: function(target) Parameterstarget: The target object. Return valueReturn a Boolean value. Browser Support
Example 1<script> const proxy = new Proxy({}, { preventExtensions: function(target) { Object.preventExtensions(target); return !Object.isExtensible(target); } }); document.writeln(Object.isExtensible(proxy)); //expected output:true </script> Output: true Example 2<script> const proxy1 = new Proxy({}, { preventExtensions: function(target) { Object.preventExtensions(target); return !Object.isExtensible(target); } }); document.writeln(Object.isExtensible(proxy1)); //expected output: true document.writeln(' Output: true [object Object] false Example 3<script> var x = { first: false }; var y ={ preventExtensions(target) { target.canEvolve = false; Object.preventExtensions(target); return true; } }; var proxy = new Proxy(x, y); document.writeln(x.first); // expected output: false Object.preventExtensions(proxy); document.writeln(" Output: false false
Next TopicJavaScript handler
|