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

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

大神們可以幫我看看為什么t-hello 不能顯示嗎 謝謝

(function () {
? ?var n="李四"; ?//新變量

? ?function person(name) { ? ?//傳遞參數
? ? ? ?var _this={};
? ? ? ?_this._name=name; ? ? //傳遞參數
? ? ? ?_this.say=function () {
? ? ? ? ? ?alert("p-hello"+_this._name+n);//傳遞參數 ?//加入新變量

? ? ? ?};
? ? ? ?return _this;
? ?}
? ?window.person=person;
}());


(function () {
? ?function teacher(name) {
? ? ? ?var _this=person(name);
? ? ? ?var superHello=_this.say;
? ? ? ?_this.say=function () {
? ? ? ? ? ?superHello.call(_this);
? ? ? ? ? ?alert("t-hello"+_this._name+n);

? ? ? ?};
? ? ? ?return _this;
? ?}
? ?window.teacher=teacher;

}());

var t=teacher("張三"); ? //傳遞參數
t.say();

正在回答

1 回答

????好像是因為你上面的那個【var n="李四";】的位置的問題,那個位置的【n】應該是個局部變量,離開了它所在的函數之后就被清除了。就不存在了。

????然后導致下面的【alert("t-hello"+_this._name+n);】中【+n】出錯。從而導致【t-hello不顯示】。

????解決方法是,把【var n="李四";】這條語句,移到兩個函數的外面去,改成全局變量。

????比如移到【var t=teacher("張三"); ? //傳遞參數】的上面。

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

舉報

0/150
提交
取消

大神們可以幫我看看為什么t-hello 不能顯示嗎 謝謝

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

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

幫助反饋 APP下載

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

公眾號

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