//函数的初始化要比变量的优先级高 /* function f1(){} var f1 - undefined; */ function f1(){ console.log(2); } //匿名函数 var f1 = function (argument) { // body... console.log(1); } f1(); //自执行函数的调用两种 /* !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();