In this post I read that objects too have attributes like prototype
, class
and extensible
.
They're not called "attributes" normally but internal slots. Usually they are denoted by double brackets to differentiate them from normal properties, i.e. [[prototype]], [[class]] and [[extensible]].
What is the [[class]] attribute? Is there such attribute?
Not in ES6 any more. The [[class]] internal slot contained information on which kind of builtin type (e.g. Array, RegExp, builtin wrapper) the object was. It was shown when you used the Object.prototype.toString
method on the object. (Have a look at Why can Object.prototype.toString.call(foo) detect foo's type? or Why does `Object.prototype.toString` always return `[object *]`? for more details - it was also the best way to detect whether an object is an array before Array.isArray
was available).
Since ES6, there is no such internal slot any more and Object.prototype.toString
relies on the Symbol.toStringTag
mechanism now.
And isn't extensible a method of object as isExtensible()?
No, the [[extensible]] internal slot is the thing that isExtensible()
accesses, and that Object.preventExtensions()
can set.