Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.在JavaScript中调用(此)习惯用法_Javascript_Node.js_Passport.js - Fatal编程技术网

.在JavaScript中调用(此)习惯用法

.在JavaScript中调用(此)习惯用法,javascript,node.js,passport.js,Javascript,Node.js,Passport.js,在一些JavaScript中,我看到: var passport = require('passport') function Strategy(options, verify) { //... passport.Strategy.call(this); } 什么是passport.Strategy.call(this)do?函数.call()是一个本机javascript函数,它将上下文传递给函数。在这种情况下,调用函数passport.Strategy(),并传递this的上下

在一些JavaScript中,我看到:

var passport = require('passport')

function Strategy(options, verify) {
  //...

  passport.Strategy.call(this);
}
什么是
passport.Strategy.call(this)
do?

函数
.call()
是一个本机javascript函数,它将上下文传递给函数。在这种情况下,调用函数
passport.Strategy()
,并传递
this
的上下文

这意味着在
passport.Strategy()
函数中,
这个
对象引用了第一个传递给
.call()
函数的变量。

函数是一个本机javascript函数,它将上下文传递给函数。在这种情况下,调用函数
passport.Strategy()
,并传递
this
的上下文


这意味着在
passport.Strategy()
函数中,此
对象引用了传递给
.call()
函数的第一个变量。

在该代码的上下文中,这是执行超级构造函数的有效方法。以对象为例,passport本地类的原型继承自Strategy原型。实际上,这是passport.Strategy的“子类”。创建passport.Local的新实例时,还需要执行超级构造函数(passport.Strategy)。调用(上下文)
允许您在子类的上下文中执行超级构造函数。

在该代码的上下文中,这是执行超级构造函数的有效方法。以对象为例,passport本地类的原型继承自Strategy原型。实际上,这是passport.Strategy的“子类”。创建passport.Local的新实例时,还需要执行超级构造函数(passport.Strategy)。执行
constructor.call(context)
允许您在子类的上下文中执行超级构造函数。

它正在
这个
上定义实例属性。请参见假设
passport.Strategy
是一个“基本”类,用户定义的
Strategy
应该是一个“扩展”,它基本上为扩展类提供了基本类的特性,您可以在tooBegi上找到解释:
call
调用中的给定函数,并为调用定义了
this
。这似乎是一个“基类构造函数调用”。这是如何定义“这个实例属性”的?你有两个答案,说明了明显不同的事情,我想指出它们可能都是正确的。尼尔斯正确地指出了我们唯一能确定的事情<代码>passport.Strategy
被调用,而
this
对象被设置为调用
Strategy
时使用的
this
对象。这是我们完全可以肯定的。但是badsyntax也很可能是正确的,因为
策略
的大写表示这是为了在
策略
构造函数中作为构造函数运行
passport.Strategy
。它在
上定义实例属性。请参见假设
passport.Strategy
是一个“基本”类,用户定义的
Strategy
应该是一个“扩展”,它基本上为扩展类提供了基本类的特性,您可以在tooBegi上找到解释:
call
调用中的给定函数,并为调用定义了
this
。这似乎是一个“基类构造函数调用”。这是如何定义“这个实例属性”的?你有两个答案,说明了明显不同的事情,我想指出它们可能都是正确的。尼尔斯正确地指出了我们唯一能确定的事情<代码>passport.Strategy
被调用,而
this
对象被设置为调用
Strategy
时使用的
this
对象。这是我们完全可以肯定的。但是badsyntax也很可能是正确的,即
策略
的大写表示这是为了在
策略
构造函数中作为构造函数运行
passport.Strategy