C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
JavaScript Reflect.preventExtensions() MethodThe static Reflect.preventExtensions() method is used prevent future extensions to the object. This method is same as Object.preventExtensions() method. Syntax:Reflect.preventExtensions(obj) Parameters:Obj: It is the object on which to prevent extensions. Return value:This method returns true if the target was successfully set to prevent extensions. Otherwise, this method returns false. Exceptions:A TypeError, if the target is not an Object. Browser Support:
Example 1const u = {}; console.log ( Reflect.isExtensible ( u ) ); Reflect.preventExtensions ( u ); console.log ( Reflect.isExtensible ( u ) ); Output: true false Example 2const obj = {"p":3,"q":4}; Reflect.preventExtensions(obj); console.log ( obj.hasOwnProperty ( "p" ) ); delete obj.p; console.log ( obj.hasOwnProperty ( "q" ) ); Output: true true Example 3const uu = {}; Reflect.preventExtensions(uu); console.log( Reflect.isExtensible(uu) ); // add a property uu.pp = 3; console.log( uu.hasOwnProperty ("pp") ); Output: false false
Next TopicJavaScript Reflect
|