javascript - function() exists but prototype function() doesn't exist. Why? -


i creating javascript class called imagerotatormanager manage dynamically-loaded slideshow. when loading images via xml, have following functions defined:

/* loads configuration settings image rotator */ imagerotatormanager.prototype.loadxml = function (callback) {     jquery.get("assets/image-rotator.xml", {}, function (xml) {             parsexml(xml, callback); //the callback function                                                  }); };  /* loads configuration settings image rotator */ function parsexml(xml, callback) {     //find every image , add image '#slideshow' div }; 

the function parsexml(xml, callback) called successfully.

however if define parsexml() imagerotatormanager.prototype.parsexml = function (xml, callback) , call function using imagerotatormanager.parsexml(xml, callback);, receive following error:

imagerotatormanager.parsexml not function

why error? make other function calls using signature , work fine.

you can't call .parsexml() way.

you've added prototype must call on instance of class, not using class name itself.

try this:

imagerotatormanager.prototype.loadxml = function (callback) {     var self = this;     jquery.get("assets/image-rotator.xml", {}, function (xml) {         self.parsexml(xml, callback); //the callback function     }); }; 

Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -