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

JS nested function call context problem solving_javascript skills

WBOY
Release: 2016-05-16 16:54:27
Original
1014 people have browsed it
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();

}

}





Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template