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
Post a Comment