Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于一段代码的疑问? #6

Open
xiaoyann opened this issue Mar 31, 2016 · 1 comment
Open

关于一段代码的疑问? #6

xiaoyann opened this issue Mar 31, 2016 · 1 comment

Comments

@xiaoyann
Copy link

先说声不好意思,在issue里提这样的问题
源码

var name = 'img_' + (+new Date());
        entry[name] = image;
        image.onload = image.onerror = function () {
            entry[name] =
                image =
                image.onload =
                image.onerror = null;
            delete entry[name];
        };

为什么要将 image 挂在entry对象上?然后是这个函数执行完后image不就销毁了吗?为什么还要通过监听onload和onerror来销毁?

@xiaoyann
Copy link
Author

我明白了,正是因为image会被销毁,请求有可能被阻止发不出去,所以需要将image保持在一个对象上。
一开始这样想过,但测试了下请求是正常的,直到刚刚看到这篇文章用new Image().src作LOG统计的一个注意事项

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant