Home  >  Article  >  Web Front-end  >  JS nested function call context problem solving_javascript skills

JS nested function call context problem solving_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:54:27989browse
Copy code The code is as follows:





Document

< ;script>
var stu ={
m: function(){
var self = this;
console.log(this === stu); // ==> true;
function f(){
// When calling a nested function, this does not point to the context of calling the outer function
console.log(this === stu); // ==> false;
If you want to access the this of the external function, you need to save the this of the external function in a variable.
console.log(self === stu); // ==> true;
}
f();

}

}





Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn