In some JavaScript I see:
var passport = require('passport')
function Strategy(options, verify) {
//...
passport.Strategy.call(this);
}
What is passport.Strategy.call(this);
doing?
In some JavaScript I see:
var passport = require('passport')
function Strategy(options, verify) {
//...
passport.Strategy.call(this);
}
What is passport.Strategy.call(this);
doing?
In the context of that code, this is effectively a way to execute the super constructor. Looking at the passport-local object for example, the passport-local class's prototype inherits from the Strategy prototype. Effectively it's a "sub-class" of passport.Strategy. When you create a new instance of passport.Local, you will also want to execute the super constructor (passport.Strategy). Doing constructor.call(context)
allows you to execute the super constructor in the context of the sub-class.
The .call()
function is a native javascript function which passes the context to the function. In this case the function passport.Strategy()
is called and the context of this
is passed.
This means that within the passport.Strategy()
function the this
object refers to the first passed variable to the .call()
function.