开发者

underscore.js _.values method reverses the order

The _.values function of underscore.js reverses the order of values returned.

Does anyone know the reas开发者_如何学JAVAon behind this behavior?


_.values works on objects. The order of properties is not defined (it is implementation-dependent and may vary even within an implementation in non-obvious ways). From section 12.6.4 ("The for-in statement") of the ECMAScript specification:

The mechanics and order of enumerating the properties...is not specified.

Underscore either uses for..in or Object.keys to get the property names, and then get the values. The order of Object.keys is slaved to the order of for..in (see Section 15.2.3.14).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜