开发者

What is the double-dot operator (..) in Javascript?

I'm doing some work with the Parser API in Spidermonkey. The docs show that there's a binary operator ... Anybody have any idea what 开发者_JS百科this is/does? I'd love to know. I've never seen it before. If I were forced to guess, I'd have to say it's something with E4X, but that's only because I know nothing about E4X.


Not to be confused with the decimal point and dot:

var val= 1000..toExponential()


It is an E4X operator.

From https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide:Processing_XML_with_E4X:

While the . operator accesses direct children of the given node, the .. operator accesses all children no matter how deeply nested:


Something like:

255..toString(16);

First dot is actually a decimal point, just let JavaScript Compiler know the second dot wants to invoke property or method. And 255.toString(16) makes JavaScript Compiler confused(identifier starts immediately after decimal numeric literal).


It is indeed E4X. It does the same thing as the single dot operator, which selects children, but it selects all descendants. (It's by analogy with XPath's / operator selecting children of an element that match the selector and // selecting all descendants that match the selector.)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜