Cannot read property 'order' of undefined (48)/ Cannot read property 'length' of undefined (7)
//圖片預(yù)加載插件 (function($){????//閉包傳遞參數(shù) function?Preload(imgs,?options)?{ var?imgs?=?(typeof?imgs?===?'string')???[imgs]?:?imgs;??//傳入對象為字符串 var?opts?=?$.extend({},?Preload.DEFAULTS,?options);?????//將默認(rèn)的參數(shù)和傳遞進(jìn)來的參數(shù)合并-->后者覆蓋前者 if?(this.opts.order?===?'ordered')?{??????//判斷使用有序還是無序???<--?這里為什么讀不到order呢? this._oredered(); }?else?{ this._unordered(); } //?this._unordered(); } Preload.DEFAULTS?=?{ order:?'unordered',?//默認(rèn)使用無序預(yù)加載 each:?null,?//?每一張圖片加載完成 all:?null?//所有圖片加載完成 }; Preload.prototype._oredered?=?function?()?{????//有序預(yù)加載 var?imgs?=?this.imgs, opts?=?this.opts, count=?0, len?=?imgs.length;??????//<--這里??imgs怎么傳遞的?我這里是undefined sortPreLoad(); function?sortPreLoad?()?{ var?imgObj?=?new?Image(); $(imgObj).on('load?error',?function?()?{ opts.each?&&?opts.each(count);?????????//存在each方法,傳入count?????? if(count?>=?len?-?1)?{????//如果圖片加載完成 opts.all?&&?opts.all(); }?else?{ sortPreLoad(); } count++; }); imgObj.src?=?imgs[count]; }; } Preload.prototype._unordered?=?function?()?{?//無序加載 var?imgs?=?this.imgs, opts?=?this.opts, count?=?0; alert(this.imgs) var?len?=?imgs.length; $.each(imgs,?function?(i,?src)?{ if(typeof?src?!=?'string'){ return?; } var?imgObj?=?new?Image(); $(imgObj).on('load?error',?function?()?{ opts.each?&&?opts.each(count); if(count?>=?len?-1)?{ opts.all?&&?opts.all(); } count++; }); imgObj.src?=?src; }); }; $.extend({ preload:?function?(imgs,?opts)?{ new?Preload(imgs,?opts); } }); })(jQuery)
preload.js:48 Uncaught TypeError: Cannot read property 'length' of undefined ? ?
at Preload._unoredered (preload.js:48) ? ?
at new Preload (preload.js:12) ? ?
at Function.preload (preload.js:72) ? ?
at index.html:100
-----
preload.js:7 Uncaught TypeError: Cannot read property 'order' of undefined ? ?
at new Preload (preload.js:7) ? ?
at Function.preload (preload.js:70) ? ?
at index1.html:74
2017-05-18
這不是已經(jīng)告訴你錯誤在哪了嗎?