第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

用“ var that = this”理解Javascript范圍

用“ var that = this”理解Javascript范圍

犯罪嫌疑人X 2019-11-28 13:47:59
說我在對(duì)象中具有以下屬性方法:  onReady: function FlashUpload_onReady()  {     Alfresco.util.Ajax.jsonGet({       url: Alfresco.constants.PROXY_URI + "org/app/classification",       successCallback: {         fn: function (o) {           var classButtonMenu = [],               menuLabel, that = this;           var selectButtonClick = function (p_sType, p_aArgs, p_oItem) {               var sText = p_oItem.cfg.getProperty("text");               that.classificationSelectButton.set("label", sText);           };           for (var i in o.json.items) {             classButtonMenu.push({               text: o.json.items[i].classification,               value: o.json.items[i].filename,               onClick: {fn: selectButtonClick}             });           }           this.classificationSelectButton = new YAHOO.widget.Button({             id: this.id + "-appClassification",             type: "menu",             label: classButtonMenu[0].text,             name: "appClassification",             menu: classButtonMenu,             container: this.id + "-appClassificationSection-div"           });         },         scope: this       },       failureMessage: "Failed to retrieve classifications!"     });我花了一些猜測(cè)才能弄清楚在selectButtonClick我需要引用的函數(shù)中(that而不是this為了獲得訪問權(quán))this.classificationSelectButton(否則就會(huì)出現(xiàn)undefined),但是我不確定為什么不能使用this。我最好的猜測(cè)是,new YAHOO.widget.Button一旦調(diào)用了構(gòu)造函數(shù),整個(gè)對(duì)象中任何被某種方式引用的屬性都會(huì)失去作用域。有人可以解釋為什么我必須引用classificationSelectButton它var that = this而不是僅僅調(diào)用`this.classificationSelectButton'嗎?
查看完整描述

3 回答

?
偶然的你

TA貢獻(xiàn)1841條經(jīng)驗(yàn) 獲得超3個(gè)贊

因?yàn)?code>this根據(jù)其運(yùn)行的上下文更改其值。

selectButtonClick函數(shù)內(nèi)部,this將引用該函數(shù)的上下文,而不是外部上下文。因此,您需要this在外部上下文中給不同的名稱,該名稱可以在selectButtonClick函數(shù)內(nèi)部被引用。


查看完整回答
反對(duì) 回復(fù) 2019-11-28
  • 3 回答
  • 0 關(guān)注
  • 913 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)