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

关于javascript数组的最大索引 #7

Closed
yan-jie opened this issue Jun 2, 2016 · 3 comments
Closed

关于javascript数组的最大索引 #7

yan-jie opened this issue Jun 2, 2016 · 3 comments
Labels

Comments

@yan-jie
Copy link

yan-jie commented Jun 2, 2016

underscore源码翻译版本中,224行翻译说javascript中数组的最大长度为Math.pow(2,53)-1,但是我在控制台上测试过,出现异常
image
在ECMA262标准中,length的最大长度应该为 Math.pow(2,32)-1
参考链接

@lessfish
Copy link
Owner

lessfish commented Jun 2, 2016

的确,你是对的。这点我也不大理解,源码给了个链接 http://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength,你可以看下有没有用?(我是没大看明白)

@hankxdev
Copy link

hankxdev commented Jun 2, 2016

underscore 这里不是判断array,更多是对array-like(类数组?)对象的判断。因此,数组的最大长度依然是 Math.pow(2,32)-1, 而这里的 Math.pow(2,53)-1是针对其他array like对象的。另外这里的Math.pow(2,53)-1 严格来说也不是array like 对象的最大长度值,而是一个“最安全整数” (MAX_SAFE_INTEGER )https://tc39.github.io/ecma262/#sec-number.max_safe_integer

@lessfish
Copy link
Owner

lessfish commented Jun 2, 2016

@HangYang 棒!感谢指出 到时说到这一部分的时候再重点讲下 再次感谢!

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

No branches or pull requests

3 participants