JS嵌套函数调用上下文的问题
来源:互联网 发布:黑莓怎么改网络标识 编辑:程序博客网 时间:2024/05/18 17:45
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<script>
var stu ={
m: function(){
var self = this;
console.log(this === stu); // ==> true;
function f(){
// 调用嵌套函数时this不是指向调用外层函数的上下文
console.log(this === stu); // ==> false;
如果想访问外部函数的this需要将外部函数的this保存在一个变量中。
console.log(self === stu); // ==> true;
}
f();
}
}
</script>
<body>
</body>
</html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<script>
var stu ={
m: function(){
var self = this;
console.log(this === stu); // ==> true;
function f(){
// 调用嵌套函数时this不是指向调用外层函数的上下文
console.log(this === stu); // ==> false;
如果想访问外部函数的this需要将外部函数的this保存在一个变量中。
console.log(self === stu); // ==> true;
}
f();
}
}
</script>
<body>
</body>
</html>
- JS嵌套函数调用上下文的问题
- 函数嵌套调用遇到的问题
- 【JS】【Core】函数,函数调用上下文this,闭包
- 模板函数的嵌套调用
- C++ 函数的嵌套调用
- 函数的嵌套与调用
- PHP函数的嵌套调用
- C++函数的嵌套调用
- js中call和apply(函数的上下文调用模式)详解
- js中call和apply(函数的上下文调用模式)详解
- jar 的嵌套调用问题
- JS:apply()二、函数的上下文
- JS中关于函数调用的问题
- xdebug 嵌套函数调用级数问题
- c++中的函数嵌套调用和嵌套定义问题
- JS的setInterval嵌套问题
- python函数的嵌套调用与嵌套定义
- JS嵌套调用
- ORACLE数据库密码忘记了的解决方法
- .net 评分计算--使用配置公式进行计算
- LAV Filter 源代码分析 2: LAV Splitter
- mahout kmeans 测试
- poj 1703 - Find them, Catch them(并查集)
- JS嵌套函数调用上下文的问题
- WOW6432Node真身
- nagiosgraph nan
- Dom4j 使用简介
- xml数据和xml文件的解析
- Visual Studio 2010挂不上Nunit断点问题
- java基础——多线程(两种传统方式)
- GCD实战一:使用串行队列实现简单的预加载
- 数据库基本操作2