//自执行函数的调用三种 /* !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();
原文地址:https://www.cnblogs.com/mengdiezhuangzhou/p/9829115.html
时间: 2024-10-13 15:01:34