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

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

bind 這里,可以不用fNOP函數嗎?

稍微修改了代碼試了一下,結果也是一樣的,請問為什么polyfill寫法要fNOP呢?

Function.prototype.myBind?=?function(_that){??var?fn?=?this;?//?fn?=?foo??var?_arguments?=?Array.prototype.slice.call(arguments).slice(1)??var?fNOP?=?function(){},??????fBound?=?function(){????????console.log(this)?????????var?that?=?this?instanceof?fn?&&?_that???this?:?_that;?????????var?args?=?Array.prototype.slice.call(arguments)????????var?bindArgs?=?_arguments.concat(args)????????return?fn.apply(that,?bindArgs)??????};??fBound.prototype?=?new?fn();?//?fBound繼承了fNOP的原型,也就是fn的原型,去修正返回的fBound函數的prototype對象??return?fBound;}function?foo(){??this.b?=?100;??return?this.a}var?func?=?foo.bind({a:1})func()new?func()


正在回答

1 回答

Function.prototype.myBind?=?function(_that){
??var?fn?=?this;?//?fn?=?foo??
??var?_arguments?=?Array.prototype.slice.call(arguments).slice(1)
??var?fBound?=?function(){
??????console.log(this)?????????
??????var?that?=?this?instanceof?fn?&&?_that???this?:?_that;
??????var?args?=?Array.prototype.slice.call(arguments)????????
??????var?bindArgs?=?_arguments.concat(args)????????
??????return?fn.apply(that,?bindArgs)??????
????};??
??????fBound.prototype?=?new?fn();?//?fBound繼承了fNOP的原型,也就是fn的原型,去修正返回的fBound函數的prototype對象??
??????return?fBound;
????}
????
????function?foo(){??
??????this.b?=?100;??
??????return?this.a
????}
????var?func?=?foo.bind({a:1})
????func()?
????new?func()

上面提問的代碼格式錯亂了,下面這里是正確排版,沒有用fNOP也可以得到一樣的效果,為什么需要用fNOP函數呢?

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

bind 這里,可以不用fNOP函數嗎?

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

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

幫助反饋 APP下載

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

公眾號

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