I am new to JavaScript. New, as far as I really did with it, is to modify existing code and write small jQuery snippets.
Now I'm trying to write a "class" with attributes and methods, but I'm having problems with methods. My code is:
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', }); }; } Request.prototype.start = function() { if( this.stay_open == true ) { this.open({msg: 'listen'}); } else { } };
The problem is in Request.prototype.start , this is undefined, and therefore the if statement evaluates to false. What am I doing wrong here?
javascript prototype class
Carson Myers Oct 25 '10 at 3:48 2010-10-25 03:48
source share