注意:根据ECMAScript5.1,第15.1.1.3节,window.undefined是只读的.
当我最近将Facebook Connect与Tersus集成时,我最初收到错误消息,Invalid Enumeration Value并Handler already exists在尝试调用Facebook API函数时.
事实证明,问题的原因是
object.x === undefined
Run Code Online (Sandbox Code Playgroud)
当'object'中没有属性'x'时返回false.
我通过在两个Facebook函数中用常规相等替换严格相等来解决这个问题:
FB.Sys.isUndefined = function(o) { return o == undefined;};
FB.Sys.containsKey = function(d, key) { return d[key] != undefined;};
Run Code Online (Sandbox Code Playgroud)
这使得事情对我有用,但似乎暗示了Facebook的JavaScript代码和我自己的代码之间的某种冲突.
什么可能导致这个?
提示:这是有据可查的undefined == null同时undefined !== null.这不是问题.问题是我们如何得到undefined !== undefined.
我有一个 Tampermonkey 脚本,可以向基于浏览器的游戏添加一些信息。我使用一段简单的代码根据玩家的区域设置向数字添加千位分隔符:
function nThousand(x) {
return x.toLocaleString();
}
Run Code Online (Sandbox Code Playgroud)
这个函数在很多代码中都会用到,例如:
$("#CustomStats" + stat).html(
"<b>" + texts[lang].stat_points_need + ":</b> " + nThousand(remainingPoints) + "<br />" +
"<b>" + texts[lang].money_need + ": </b>" + nThousand(remainingMoney) + "<br />" +
"<b>" + texts[lang].money_spent + ": </b>" + nThousand(currentMoney) + "<br /><br />" +
"<b>" + texts[lang].bought_points + ": </b>" + nThousand(boughtPoints) + "<br />" +
"<b>" + texts[lang].equipment_points + ": </b>" + nThousand(itemPoints) + "<br />" +
"<b>" + texts[lang].points_from_level + ": </b>" …Run Code Online (Sandbox Code Playgroud)