javascript的this指向
来源:互联网 发布:java urlencode转码 编辑:程序博客网 时间:2024/05/16 14:25
var myObject={
foo:”bar”,
func:function(){
var self=this;
console.log(this.foo);
console.log(self.foo);
(function(){
console.log(this.foo);
console.log(self.foo);
}());
}
};
myObject.func();
console.log控制台打印的值为bar bar undefined bar
第一个this.foo输出bar,因为当前this指向对象myObject.
第二个self.foo输出bar,因为self是this的副本,同指向myObject对象。
第三个this.foo输出undefined,因为这个IIFE(立即执行函数表达式)中的this是指向window。
第四个self.foo输出bar,因为这个匿名函数所处的上下文中没有self,所以通过作用域链向上查找,从包含它的父函数中找到了指向myObject对象的self.
阅读全文
0 0
- JavaScript-this的指向
- javascript的this指向
- javascript this的指向
- 浅谈javascript的this指向
- javascript 中 this 的指向
- javascript 有关this的指向
- JavaScript中 this 的指向
- JavaScript中this的指向
- javascript中this的指向
- javascript 的 this 指向问题
- javaScript中this的指向
- Javascript中this的指向
- JavaScript的三种this指向问题
- 准确理解javascript中的this的指向
- 关于javascript的this指向问题
- javascript中this的指向问题
- javascript中this指向问题的综合
- JavaScript中this的指向问题
- 表结构 shopnc
- poj3126(bfs)
- 《深入理解Java虚拟机》个人读书总结——垃圾收集/回收算法
- 程序员面试金典:双栈排序、二叉平衡检查、输出单层节点
- MySQL 中 You can't specify target table '表名' for update in FROM clause错误解决办法
- javascript的this指向
- 数组中只出现一次的数字(java版)
- SVN---开发必用
- (80)蓝图剖析
- Spring 设计模式之适配器
- Google protobuf
- WebRTC源码分析一:音频处理流程
- 百度实名制
- linux下查找并杀掉tomcat进程