Ashan Priyadarshana
Ashan Priyadarshana

Reputation: 3619

Javascript object attributes?

I know that all object properties have a name and have attributes like value, configurable, enumerable and writable. But in this post I read that objects too have attributes like prototype, class and extensible.

I understand that prototype attribute is for pointing for the parent object. But what I don't understand is what's class attribute? Is there such attribute? And isn't extensible is a method of object as isExtensible() ?

Upvotes: 1

Views: 154

Answers (1)

Bergi
Bergi

Reputation: 664444

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.

Upvotes: 6

Related Questions