function Message() {
this._list=[];
this.msg='hello'
}
Message.prototype.attach=function (hero) {
this._list.push(hero)
};
Message.prototype.notify=function () {
for (var i=0;i<this._list.length;i++){
this._list[i].update();
}
};
Message.prototype.setState=function (msg) {
this.msg=msg;
this.notify()
};
Message.prototype.getState=function () {
return this.msg
};
呼叫后顯示this._list[i].update is not a function
uj5u.com熱心網友回復:
那就看你的this._list陣列里面放的是什么了,放的元素的原型鏈上必須要有update方法,否則就會報錯。轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/68819.html
標籤:JavaScript
上一篇:哥哥們,canvas 在chrome預覽時 Cannot read property 'getContext' of null怎么解決
下一篇:網站HTML引入遠端js函式后,在網頁另存為后,js函式就會嵌入式在index.html主頁中,怎么讓js函式不嵌入式頁面中?
