Переопределение переменной в объекте
Никак не могу понять почему у меня не переопределается переменная.
Есть скрипт var lazyLoad = (function () { function work(options){ window.d = document var buffer = '' d.write = d.writeln = function(s){ buffer += s } d.open = d.close = function(){} s = d.createElement('script') s.setAttribute('type','text/javascript') s.setAttribute('src',options.url) d.getElementById(options.block).appendChild(s) s.onload = function () { window.setTimeout(function() { d.getElementById(options.block).innerHTML += buffer }, 0) } } return { init: function (options) { var CONFIG = { url: '', block: '' } $.extend(CONFIG, options) random = $('#'+CONFIG.block).attr('rel') id = $('#'+CONFIG.block).attr('id').replace(random,'') id = id.replace('DIV','') size = id.split('X') ele_width = size[0] || CONFIG.width ele_height = size[1] || CONFIG.height $('#'+CONFIG.block).css({ 'width':ele_width+'px', 'height':ele_height+'px', 'background':'url(/static/i/ajax-loading-black.gif) no-repeat center center' }) $(window).load(function(){ if(options.adfox) { random = $('#'+CONFIG.block).attr('id').replace('AdFox_banner_','') AdFox_getCodeScript(1, random, CONFIG.url) }else{ work(options) } }) } } })(); Вызываю я его так: lazyLoad.init({ url: 'http://example.com/test1.js', block: DIVID1 }) Потом так: lazyLoad.init({ url: 'http://example.com/test2.js', block: DIVID2 }) После второго вызова переменная buffer есть и все успешно вставляется в div, но после первого ничего не происходит. Т.Е. Код:
<script> |
Часовой пояс GMT +3, время: 17:36. |