亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

想參照老師的代碼打一下,看看arugments,結果提示SyntaxError: Unexpected token this,跪求解決

function?foo(){
??this.b=100;
??retrun?this.a;
}
var?func=foo.binddd({a:1});
Function.prototype.binddd=function(oThis){
??var?aArgs=Array.prototype.slice.call(arguments,1);
??fToBind=this;
??fNOP=function(){};
??Bound=function(){
????return?fToBind.apply(this?instanceof?fNOP?this:oThis,aArgs.concat(Array.prototype.slice.call(arguments)));
??}
??fNOP.prototype=this.prototype;
??fBound.prototype=new?fNOP();
??return?fBound;
};
func();
new?func();


正在回答

1 回答

function?foo(){
??this.b=100;
??return?this.a;
??//retrun打錯了
}
var?func=foo.bind({a:1});
//binddd打錯了
Function.prototype.bind=function(oThis){
??//binddd打錯了
??var?aArgs=Array.prototype.slice.call(arguments,1);
??fToBind=this;
??fNOP=function(){};
??Bound=function(){
????return?fToBind.apply(this?instanceof?fNOP?this:oThis,aArgs.concat(Array.prototype.slice.call(arguments)));
??}
??fNOP.prototype=this.prototype;
??fBound.prototype=new?fNOP();
??return?fBound;
};
console.log(func());//->1
console.log(new?func())//->[object?Object]?{b:?100}(bind失效,忽略return,直接返回this{b=100}的對象)


1 回復 有任何疑惑可以回復我~
#1

風魔大王 提問者

一直把注意力放在this了,沒想到是打錯了,還想著用著兼容好的瀏覽器想亂輸個binddd試試的,經測試不行,按您說的改就成功了,萬分感謝!
2016-11-30 回復 有任何疑惑可以回復我~
#2

風魔大王 提問者

非常感謝!
2016-12-01 回復 有任何疑惑可以回復我~
#3

慕移動4113297 回復 風魔大王 提問者

我去,好的瀏覽器使用了兼容binddd的嗎?那是不是可以寫functionnn,thisss,forrr,ifff了!
2018-10-13 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

想參照老師的代碼打一下,看看arugments,結果提示SyntaxError: Unexpected token this,跪求解決

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號