How to bind `this` and private variables?

Is it possible to get any attachment to thisand all closed variables from a function?

eg.

 function f() { console.log(this); }
 let x = f.bind(7);
 function g() { console.log(x); }
  • Can this 7one be extracted from x?

  • gcloses over x. Is it possible to get an array of private variables from g?

+4
source share
1 answer

Can this 7one be extracted from x?

Nope. fshould explicitly tell you the way to get this(e.g. function f() { return this; }). Since this is not so, you cannot.

, [[BoundThis]] . [[BoundThis]] : , [[Call]] . , , .

g x. g?

.:-) API.

lexical environment, g, . .


, , ( ), TC39 (, ) ( ).

+9

Source: https://habr.com/ru/post/1666286/


All Articles