var objectPoolFactory = function (createObjFn) {
            var objectPool = [];
            return {
                create: function () {
                    var obj = objectPool.length === 0 ? createObjFn.apply(this, arguments) : objectPool.shift();
                    return obj;
                },
                recover: function (obj) {
                    objectPool.push(obj);
                }
            };
        };

        var iframeFactory = objectPoolFactory(function () {
            var iframe = document.createElement('iframe');
            document.body.appendChild(iframe);

            iframe.onload = function () {
                iframe.onload = null;
                iframeFactory.recover(iframe);
            };
            return iframe;
        });

        var iframe1 = iframeFactory.create();
        iframe1.src = 'http://www.baidu.com';

        var iframe2 = iframeFactory.create();
        iframe2.src = 'http://www.sina.com';

        setTimeout(function () {
            var iframe3 = iframeFactory.create();
            iframe3.src = 'http://www.qq.com';
        }, 10000);

 

相关文章:

  • 2022-12-23
  • 2021-10-09
  • 2021-05-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-29
猜你喜欢
  • 2021-11-28
  • 2022-12-23
  • 2021-11-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案