简体   繁体   English

词汇与此相反

[英]The opposite of lexical this

This is a question about terminology. 这是关于术语的问题。

Considering that there is a method that uses lexical this : 考虑到有一个使用词法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? 什么是对传统的术语this时候,当被绑定到不同的环境或脱离被调用的方法?

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 . 的词汇相对this动态 this

However, notice that lexical this is not what you have shown in your function snippet, it's the this that arrow functions have. 但是,请注意词法this是不是你已经在你出什么function片段,它的this那个箭头功能都有。

You don't need different terms to describe the behavior of JS lexical this for what it is referring to. 你并不需要使用不同的术语来描述JS词汇的行为, this东西它是指。 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. 它总是在“背景”的函数被调用让它成为父对象或其他结合-你总是可以说词法this表示的上下文。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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