+ JavaScript の質問用スレッド vol.97 +at HP
+ JavaScript の質問用スレッド vol.97 + - 暇つぶし2ch135:Name_Not_Found
12/01/30 18:12:44.99 QZ0U/9Kn
★の部分のthisがBBS内のthisじゃなくてクリックされた要素になるんだけど
clickのイベントハンドラを匿名じゃないメソッドとして定義しつつ
thisをBBSと同じスコープのthisとして使う方法はない?

var BBS = function() {
 this.messages = new Array();
 this.box = $("#box");
 this.button = $("#button");
}

BBS.prototype.show = function() {
 for(var i = 0; i < this.messages.length; ++i) {
  this.box.append(this.messages[i]);
 }
 this.button.onclick(this.post);
}

BBS.prototype.post = function(ev) {
 var message = getMessage();
 this.messages.push(message); # ←★
}



次ページ
続きを表示
1を表示
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch