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

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

bind方法不是棄用了嗎?

bind方法不是棄用了嗎?

正在回答

2 回答

jquery的事件綁定方法.bind(),和視頻所講的js原生修改函數this指向的.bind(),是兩個東西啊。大兄弟,你會不會把這兩者混淆了~

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

bind?函數在 ECMA-262 第五版才被加入;它可能無法在所有瀏覽器上運行。你可以部份地在腳本開頭加入以下代碼,就能使它運作,讓不支持的瀏覽器也能使用 bind() 功能。

if (!Function.prototype.bind) {
?Function.prototype.bind = function (oThis) {
? ?if (typeof this !== "function") {
? ? ?// closest thing possible to the ECMAScript 5
? ? ?// internal IsCallable function
? ? ?throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable")
? ?}

? ?var aArgs = Array.prototype.slice.call(arguments, 1),
? ? ?fToBind = this,
? ? ?fNOP = function () {},
? ? ?fBound = function () {
? ? ? ?fBound.prototype = this instanceof fNOP ? new fNOP() : fBound.prototype ? ? ? ?return fToBind.apply(this instanceof fNOP
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? this
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? : oThis || this,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? aArgs.concat(Array.prototype.slice.call(arguments)))
? ? ? ?}
? ?if( this.prototype ) {
? ? ?// Function.prototype doesn't have a prototype property
? ? ?fNOP.prototype = this.prototype ? ?}

? ?return fBound ?}}

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

舉報

0/150
提交
取消

bind方法不是棄用了嗎?

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

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

幫助反饋 APP下載

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

公眾號

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