JavaScript: Reflect.preventExtensions

By Xah Lee. Date: . Last updated: .

New in JS2015.

Reflect.preventExtensions( obj )
Sets obj's extensible attribute to false. Return true if success, else false. If obj is not object, throw a TypeError exception.
[See also: Object.preventExtensions]

[see Prevent Adding Property]

const u = {};
console.log( Reflect.isExtensible ( u ) ); // true
Reflect.preventExtensions ( u );
console.log( Reflect.isExtensible ( u ) ); // false

Reflect.preventExtensions vs Object.preventExtensions?

What is the difference?

Object.preventExtensions( arg) does not complain if arg is not a object.

JavaScript in Depth

JS in Depth

JS Obj Reference


JS Obj Reference