js 闭包
for(var i=0;i<10;i++) { setTimeout(function(i){ console.log(i); }.bind(null,i), function(i){ var x=i*200; console.log(x); return x; }(i)); }
Object.prototype.bind1=function(context){ var that = this; return function(){ return that.apply(context,arguments); }; }; var x = function(str,p1){ console.log(str + ' : ' + p1); }; var t=x.bind1({a:'123456'}); t('aaa','bbb');
var Duck=function(){ this.walk=function(){ console.log('walk'); } } Joy=(function(parent){ var _=function(){ // parent.call(this);// 原型冒充 } _.prototype=new parent();// 原型继承 return _; })(Duck); var JoyInst=new Joy(); JoyInst.walk();