简体   繁体   中英

The opposite of lexical this

This is a question about terminology.

Considering that there is a method that uses lexical this :

var foo = {
  method: function () {
    console.log(this, ' is the context');
  }
};

foo.method();

What's the conventional term for this when the method is called when being bound to different context or detached?

bazThatAcceptsACallback(foo.method);
foo.method.bind(baz)();
(0, foo.method)();

I often refer to it as 'non-lexical this' or 'contextual this' in such cases, but I never met these or similar terms in official or trusted sources.

The opposite of lexical this is dynamic this .

However, notice that lexical this is not what you have shown in your function snippet, it's the this that arrow functions have.

You don't need different terms to describe the behavior of JS lexical this for what it is referring to. Its always the "context" the function is called in. Let it be the parent object or another binding - you can always say the lexical this represent the context.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM