JS(十七)this
2018-03-19 23:45
417 查看
写在最前面
this
函数预编译过程 this –> window全局作用域里 this –> window
call/apply 可以改变函数运行时this指向
obj.function();function()里面的this指向obj
函数预编译过程 this –> window
function test(c){ var a = 123; function b(){}; } test(); AO{ arguments:[1]; this : window; c : 1, a : 123; b : function(){}; } new test();
obj.function();function()里面的this指向obj
谁调用this 就会指向这个函数
var name = "222"; var a = { name : "111", say : function(){ console.log(this.name) } } var fun = a.say; fun();//在全局下执行 打印222 a.say();//在a调用say this指向a 打印111 var b = { name : "333", say : function(fun){ fun(); } } b.say(a.say);//因为还是没有人调用fun(),所以还是在全局下调用的fun();所以打印的是222 b.say = a.say; b.say();//可以看到的是b.say的属性值换成了a.say也就是fun(),打印的是333
相关文章推荐
- js 之 this的用法
- JS中this
- node.js npm权限问题try running this command again as root/Administrator.
- JS:what is this "Object.prototype" anyway...?
- JS中的this都有什么作用?
- js中的this
- JS中this指向规则(简单易懂)
- 五分钟看懂js关键字this
- JS中的this,call,apply
- js面向对象编程:this到底代表什么?
- JS中的this
- 理解js中this的指向
- JS中的this机制
- js基础1-深入理解javascript之this
- js中this的总结
- JS中的this好神奇,都把我弄晕了
- js使用this获取a标签id值
- 解决vue.js this.$router.push无效的问题
- 彻底理解js中this的指向,不必硬背。
- js面向对象选项卡(this的使用)