What do these mysterious double brackets mean in javascript?

2

Let's say I create a a in javascript:

var a = new Promise(function(success, error){  { sucess("Sucesso!"); })

My variable a gets the following properties:

Promise {[[PromiseStatus]]: "resolved", [[PromiseValue]]: "Sucesso!"}

But notice that they have double brackets surrounding them. I would like to know how do I get the value of properties that have this format.

    
asked by anonymous 24.04.2016 / 00:54

1 answer

2

These [[ ]] are the way to represent visual properties of the promise visually. The ECMAScript 6 specification says so :

  Internal methods and internal slots are identified within this specification using names enclosed in double square brackets [[]].

That is:

  

Internal methods are identified using their bracketed names (right brackets in PT_en).

These methods / properties are internal to Promise and can only be used / revealed through .then() or .catch() which are respectively methods called on success and failure Promise . Therefore these [[ ]] are not variables with a value but methods to be called in case of success or failure, and being called one of them the value of Promise is revealed, by exclusion of the other not called.

    
24.04.2016 / 06:51