What does ‘::’ (double colon) do in JavaScript?

后端 未结 8 2281
深忆病人
深忆病人 2020-12-01 12:10

The documentation of some JavaScript APIs shows the following snippets as an example of how to invoke some function:

相关标签:
8条回答
  • 2020-12-01 12:33

    :: has nothing to do with the number of parameters. You can do that already in JavaScript with a normal comma:

    function SomeFunction(param1, param2) {
       //...
    }
    
    SomeFunction('oneParam'); // Perfectly legal
    

    Also, based on Tzury Bar Yochay's answer, are you sure you're not looking at something like the following?

    $('this::is all one::parameter'); // jQuery selector
    
    0 讨论(0)
  • 2020-12-01 12:37

    Nothing. It is a syntax error.

    >>> alert(42342::37438)
    SyntaxError: missing ) after argument list
    
    0 讨论(0)
  • 2020-12-01 12:39

    It must be a typo for

    <button type="button" onClick="foo.DoIt('72930')">Click</button>
    
    <button type="button" onClick="foo.DoIt('42342::37438')">Click</button>
    
    0 讨论(0)
  • 2020-12-01 12:46

    It was certainly not the case at the time of your question, but right now :: is a valid ES7 operator. It's actually a shortcut for bind.

    ::foo.bar
    

    is equivalent to

    foo.bar.bind(foo)
    

    See an explanation here for examples:

    0 讨论(0)
  • 2020-12-01 12:46

    It could be using ECMAScript for XML (ECMA-357 standard) which would imply the double quotes are a XPath operator.

    See ECMAScript for XML

    0 讨论(0)
  • 2020-12-01 12:51

    In which example did you see that? So far, JavaScript does not have a double colon operator!

    The double colon replaced the single-colon selectors for pseudo-elements in CSS3 to make an explicit distinction between pseudo-classes and pseudo-elements. But that is CSS3, not JavaScript! Not At ALL!

    0 讨论(0)
提交回复
热议问题