Answer the question
In order to leave comments, you need to log in
What does the this keyword refer to?
In general, there is such an example:
'use struct';
Function.prototype.bind = function(o){
var self = this,
boundArgs = arguments;
return function() {
var args = [], i;
for (i = 1; i < boundArgs.length; i++) args.push(boundArgs[i]);
for (i = 0; i < arguments.length; i++) args.push(arguments[i]);
return self.apply(o, args);
};
};
function hello(){
return console.log(this.name);
}
var a = {
name: 'Alex'
};
var x = hello.bind(a);
x()
Answer the question
In order to leave comments, you need to log in
In this call, hello.bind, hello is an Object Function.
It refers to it.
If the function is called as a method, then the this keyword will point to the current object, if as a function, then this will point to the global object in non-strict mode and in strict to undefined.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question