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

[亡魂溺海] 提交于 2019-11-27 01:50:21

问题


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.


回答1:


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:




回答2:


Not to be confused with the decimal point and dot:

var val= 1000..toExponential()



回答3:


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




回答4:


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



来源:https://stackoverflow.com/questions/4211037/what-is-the-double-dot-operator-in-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!