Javascript 中的双点运算符 (..) 是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4211037/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the double-dot operator (..) in Javascript?
提问by mattbasta
I'm doing some work with the Parser API in Spidermonkey. The docsshow that there's a binary operator ... Anybody have anyidea 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.
我正在用 Spidermonkey 中的 Parser API 做一些工作。文档显示有一个二元运算符..。任何人有任何想法这是什么/呢?我很想知道。我以前从未见过。如果我被迫猜测,我不得不说这与 E4X 有关系,但这只是因为我对 E4X 一无所知。
采纳答案by Ming-Tang
It is an E4X operator.
它是一个 E4X 运算符。
From https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide:Processing_XML_with_E4X:
来自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:
虽然 . 运算符访问给定节点的直接子节点,.. 运算符访问所有子节点,无论嵌套有多深:
回答by kennebec
Not to be confused with the decimal point and dot:
不要与小数点和点混淆:
var val= 1000..toExponential()
回答by liuwenzhuang
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).
第一个点实际上是一个小数点,只是让 JavaScript Compiler 知道第二个点要调用属性或方法。而255.toString(16)使得JavaScript编译器混淆(标识小数点后数字文字立即启动)。
回答by Chuck
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.)
它确实是E4X。它的作用与单点运算符相同,后者选择子项,但选择所有子项。(这与 XPath 的/运算符选择与//选择器匹配的元素的子元素并选择与选择器匹配的所有后代的操作类似。)

