मैं जावास्क्रिप्ट के लिए नया हूं। जहां तक मैंने वास्तव में इसके साथ किया है, नया कोड मौजूदा कोड में tweaked है और 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
अपरिभाषित है और इस प्रकार अगर बयान गलत का आकलन। मुझसे यहां क्या गलत हो रहा है?
क्या आपके पास 'प्रोटोटाइप' में 'स्टार्ट' है? – xj9
'Request.prototype' क्या सेट है? –
मुझे नहीं पता: एस –