如何深入理解JavaScript中this的指向并灵活修改其指向?
- 内容介绍
- 文章标签
- 相关推荐
本文共计1009个文字,预计阅读时间需要5分钟。
目录 + this 方法和对象中 + 隐藏的this + 严格模式 + 可以改变this指向 + this 老规矩优先看代码:方法中 + function test() { console.log(this); } + 对象中 + Person={ name: 张三, eat: function() { console.log(this); } } + 在方法中“
目录
- this
- 方法中
- 对象中
- 隐藏的this
- 严格模式
- 可以改变this指向
this
老规矩先看代码:
方法中
function test(){ console.log(this); }
对象中
Person={ name:"张三", eat:function(){ console.log(this) } }
在方法中,this表示该方法所属的对象。
本文共计1009个文字,预计阅读时间需要5分钟。
目录 + this 方法和对象中 + 隐藏的this + 严格模式 + 可以改变this指向 + this 老规矩优先看代码:方法中 + function test() { console.log(this); } + 对象中 + Person={ name: 张三, eat: function() { console.log(this); } } + 在方法中“
目录
- this
- 方法中
- 对象中
- 隐藏的this
- 严格模式
- 可以改变this指向
this
老规矩先看代码:
方法中
function test(){ console.log(this); }
对象中
Person={ name:"张三", eat:function(){ console.log(this) } }
在方法中,this表示该方法所属的对象。

