开发者

Method is not a function

I've tried code from here http://www.webreference.com/programming/javascript/gr/column3/ but firebug says - "this.preload is not a function". Why? I thought that F开发者_如何转开发unction is some sort of Object.


You perhaps forgot to also include the bit of code, further down the page, where the preload function is defined on the ImagePreloader prototype.


When you call constructor ImagePreloader() you apparently do it like this:

ImagePreloader(imageSrcs, imagesProcessing);

(Assuming imageSrcs is an array of URL's and imagesProcessing is a function with two arguments)

But ImagePreloader is a constrcutor, so you have to create new object with it so you have to type this:

new ImagePreloader(imageSrcs, imagesProcessing);

Actually, you could put resulting object to some variable, but you don't have to do that: ImagePreloader doesn't have methods which you could need to call. Also you may fear ImagePreloader will be destroyed by garbage collector without storing the object to variable, but it will not be: every Image object created by ImagePreloader.prototype.preload() will keep a link to ImagePreloader object inside its oImagePreloader propertie. ImagePreloader object will be deleted by garbage collector when all the Image objects created for you will be deleted.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜