Replies: 3 comments 12 replies
-
While researching to understand and describe the problem, it looked to me that the usage of this notation is uncommon, complex to understand, and not needed. TL;DR;We should not use the (With the exception of pages with the specification as their topic, like a page about How to document a new JavaScript feature). Reasoning
Plan
|
Beta Was this translation helpful? Give feedback.
-
IMO—they are quite unavoidable in certain places. For example, when you say "the method is defined on constructor's prototype", does that mean Also, (The consequence of avoiding This is more personal, but I still want to share it: the first time I started reading MDN systematically (i.e. not as a lookup tool for random APIs) was when I was implementing a klass—an API that tries to mimic every single behavior of JS classes. As such I needed to know every single aspect of the language's behavior, but which was surprisingly lacking on MDN. Of course 99% of our readers would not need to know what happens when you use class fields with a property already defined as non-configurable, but for those that do want to know, do we want to explain it in such a roundabout way than simply stating "it uses [[Define]]", which saves me 1 precious minute reading through the explanation and code examples? Can we instead create a page under JS references > misc like "Exotic objects and internal slots", where we document these internal slots, and then everywhere we use them, we link to this page? There are other interesting behaviors with internal slots, e.g. you cannot do |
Beta Was this translation helpful? Give feedback.
-
After mdn/content#18461 and mdn/content#18476, we have gotten rid of some pointless references. @teoli2003 Maybe you can update that table? I think the rest are more debatable. (The proxy ones are tricky—they are not very critical, but I suspect people who read these pages have a fair chance of understanding the notation anyway.) |
Beta Was this translation helpful? Give feedback.
-
The problem
JavaScript objects have what are called internal properties and accessors. These are values and functions stored on a JavaScript object, but, unlike regular properties and functions, these entities cannot be read, set, or called by any code outside the code of the engine itself.
In the specification, they are present all over the place, and on MDN, we find quite a few mentions of them. We recognize them as they are enclosed between two sets of brackets, like
[[prototype]]
,[[value]]
, or[[set]]
.The problem is the following: these mentions are information that comes out of the spec, this is not something that web developers directly deal with. At first sight, it looks like something we should bury and not display to web devs. On the other side, if authors have used them here or there (and this is not recent!), it means they are solving a problem: maybe they are more precise and succinct, and maybe they are needed to describe complex interactions.
The current situation is not good: we use these notations here or there without really explaining them, making it hard for a lot readers. We should find a solution that allows readers to naturally understand the docs (either by explaining better the internal properties when used or by hiding them).
Right now, I don't what is the best direction to take.
What questions do we want to answer in this discussion?
With this discussion, I have three objectives:
To help us make pertinent proposals, here is some extra information.
What does the spec say?
There are two kinds of them: internal methods and internal slots.
(spec)
How often are they used on MDN today?
null
.new
operator or asuper()
call.toString()
is an abstract method that can only be used onDate
objects as they need a[[TimeValue]]
internal slot. This doesn't seems to be true in ES2018 and the current draft.[[DefineOwnProperty]]
. Internal function for all objects called to create or alter an own property of the object.[[DefineOwnProperty]]
.[[PromiseState]]
. An internal slot containing the status of the promise, a state machine:pending
,fullfilled
, orrejected
. Note: This state machine is described on MDN, but doesn't use the notation[[PromiseState]]
…[[PromiseResult]]
and[[PromiseState]]
are used on MDN only in a code comment about what should be displayed on the console. This comment is outdated and doesn't describe what Chrome or Firefox dev tools does (and they display different texts).RegExp
, a boolean storing if the multiline (/m
) flag is set or not. Note: On MDN, this appears as part of a citation of the spec.cc/ @hamishwillee @Rumyra @wbamberg @sideshowbarker @Josh-Cena @schalkneethling
Beta Was this translation helpful? Give feedback.
All reactions