JavaScriptは初めてです。私が実際に行ったのは、既存のコードを微調整し、jQueryを少し書いたことだけです。
現在、属性とメソッドを使用して「クラス」を作成しようとしていますが、メソッドに問題があります。私のコード:
function Request(destination, stay_open) {
this.state = "ready";
this.xhr = null;
this.destination = destination;
this.stay_open = stay_open;
this.open = function(data) {
this.xhr = $.ajax({
url: destination,
success: this.handle_response,
error: this.handle_failure,
timeout: 100000000,
data: data,
dataType: 'json',
});
};
/* snip... */
}
Request.prototype.start = function() {
if( this.stay_open == true ) {
this.open({msg: 'listen'});
} else {
}
};
//all console.log's omitted
問題は、でRequest.prototype.start
、this
が定義されていないため、ifステートメントがfalseと評価されることです。私はここで何が間違っているのですか?
start
にはprototype
?