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

2019-01-23 04:50发布

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 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.

4条回答
Fickle 薄情
2楼-- · 2019-01-23 05:11

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:

查看更多
趁早两清
3楼-- · 2019-01-23 05:15

Not to be confused with the decimal point and dot:

var val= 1000..toExponential()
查看更多
我只想做你的唯一
4楼-- · 2019-01-23 05:15

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).

查看更多
聊天终结者
5楼-- · 2019-01-23 05:26

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.)

查看更多
登录 后发表回答