2

以下代码有什么问题?

$(function() {
    var ok = true;
    for (var i = 0; i < 1000; i++) {
        var x = 100; // if we use new Number(100) here, the test will pass
        $.each([1,2], function(k) {
            x -= 5.5; // if we use integer (or declare a variable with value 5.5 outside this scope), the test will pass
            return false;
        });
        if (x + 5.5 != 100) {
            fail();
        }
    }
});

此测试在所有浏览器中成功通过,但在 Safari 6 (6.0.2 (8536.26.17)) 中失败。代码有错误吗?还是浏览器的bug?是 jsFiddle 上的示例。它输出:

OK: 94.5 + 5.5 = 100
FAIL: 95 + 5.5 = 100
4

0 回答 0