js 在函数中遇到的this指向问题
2018-10-22 11:21
633 查看
//自执行函数的调用三种 /* !function(){ alert(123) }(); (function(){ alert(345) }()) (function(){ Array.prototype.push.call(arguments,3); console.log(arguments)//输出 [1,2,3] })(1,2) */ var obj = { a:1, b:function(){ console.log(this); } } obj.fn = function(){ console.log(this);//===obj } obj.fn(); obj.b();//this==obj //var c = obj.b();//this==obj //c();//this==window; Function.prototype.bind = function(context){ var self = this; console.log('测试bind') console.log(this); // function(){var c = 1} return function(){ return self.apply(context,arguments) } } var o = { name:'my name id huhu' } var func = function(){ alert(this.name) }.bind(o); console.log(func) //function(){return self.apply(context,argument)} func();
相关文章推荐
- JS箭头语法以及箭头函数this指向问题
- js中函数this指向问题
- js中this指向问题: (object.getName = object.getName)()为何返回“window”
- 总结js中this的指向问题
- js函数的作用域与this指向
- JS 改变函数中 this 的指向
- 理解js中this的指向问题
- JS中的this 指向问题
- Js中的this指向问题(2)
- JS函数名为click时遇到的问题
- js中this指向问题
- js 函数作用域与this 的指向实例
- JS中函数的 this 各种指向
- JavaScript的回调函数内部this的指向问题以及四种绑定this指向的方法
- js中的this指向问题及解决方案
- JS中的this指向问题以及apply、call、bind的使用
- 箭头函数、普通函数的区别以及this指向问题。
- js循环动态绑定带参数函数遇到的问题及解决方案[转]
- Js中的this指向问题
- js如何判断函数或者方法中的this指向谁?四句话