我在 Chrome 和 IE 中发生过这种情况......
如果我在 requirejs 仍在加载或获取脚本时单击链接以离开页面,我会收到随机错误。对不起,如果这是模糊的......
例如,在 require.js 本身,我今天收到一个错误:
Unable to get value of the property 'normalize': object is null or undefined
在以下块中:
//If current map is not normalized, wait for that
//normalized name to load instead of continuing.
if (this.map.unnormalized) {
//Normalize the ID if the plugin allows it.
if (plugin.normalize) {
name = plugin.normalize(name, function (name) {
return normalize(name, parentName, true);
}) || '';
}
//prefix and name should already be normalized, no need
//for applying map config again either.
normalizedMap = makeModuleMap(map.prefix + '!' + name,
我在自己定义的 js 文件中收到了其他错误,它们在完全加载依赖项之前开始执行代码。我感觉当浏览器被要求离开当前页面时,它会停止所有 ajax 调用,从而截断一些 js。
有没有办法防止这类错误?