this
来源:互联网 发布:卡通农场mac版 编辑:程序博客网 时间:2024/04/30 18:12
<script>
var point={ x:10, y:20, moveTo:function(x,y){ var moveX =function(x){ this.x =x;//this 指window } var moveY =function(y){ this.y =y; } moveX(x); moveY(y); } } point.moveTo(100,200); alert(point.x); alert(point.y); alert(x); alert(y);</script>
解析:
对于内部函数,即声明在另外一个函数体内的函数,这种绑定到全局对象的方式会产生另外一个问题。以 point 对象为例,这次我们希望在 moveTo 方法内定义两个函数,分别将 x,y 坐标进行平移。结果可能出乎大家意料,不仅 point 对象没有移动,反而多出两个全局变量 x,y。
0 0
- this
- this
- this
- this
- this
- this
- this
- this
- this
- this
- this
- $(this)
- this
- this
- this
- this
- $(this)
- this
- memcahed
- Redis与Memcached的区别
- C语言中强制数据类型转换的总结
- 二叉树的遍历
- Java 中的三目运算符
- this
- Eclipse RCP - 第一个RCP程序
- 《弟子规》全集译文,为孩子的明天存下来!
- 图片优化时注意的小问题
- scrapy抓取动态页面的事项
- REDIS缓存技术
- IOS 开发小记 ————————collection view 总结
- poj 1190 生日蛋糕
- Golang之bytes.buffer