1 日後、問題を 2 行のコードに絞り込むことができました。たぶん、私はこのステートメントを間違って使用しようとしています。
function scheduleItemView(myId){
this.update = function(show){
document.getElementById(this.id+'-title').innerHTML = show.title +": "+ show.startDate;
document.getElementById(this.id+'-title-overlay').innerHTML = show.title +": "+ show.startDate;
document.getElementById(this.id+'-description').innerHTML = truncate(show.description,190);
document.getElementById(this.id+'-time-start').innerHTML = show.startTime;
document.getElementById(this.id+'-time-end').innerHTML = show.endTime;
};
this.id=myId;
return true;
}
function nowNextView(){
this.now = new scheduleItemView('now');
this.next = new scheduleItemView('next');
this.update = function(type,args){
var myshow=args[0];
// problem is below. I have to use the global name to access the update method.
myNowNextView.now.update(myshow.now);
myNowNextView.next.update(myshow.next);
// whereas what I want to do is reference them using the "this" command like below.
// this.now.update(myshow.now);
// this.next.update(myshow.next);
// the above doesnt work. The update method in scheduleItemView is not seen unless referenced globally
// BUT even more infuriating, this.now.id does return "now" so it can access the object, just not the method
// any ideas?
};
}
オブジェクトは次にインスタンス化されます
var myNowNextView = new nowNextView();
次に、メソッドを実行します。
myNowNextView.update(stuff);
プログラムの本体内で問題を説明しようとしました。コードにエラーは発生せず、try/catch を実行する必要がありましたが、メソッドが見つからないと不承不承に告げられました。なんというかデザインがおかしい?私はこれを行うことができますか?よろしくお願いします、スティーブ