Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does colon notation work in place of a dot when executing a function?

Tags:

javascript

I know you can use the : when

  • initializing objects
  • using a ternary operator
  • using labels

Opening my console in a Chrome browser I can execute:

window.open('http://google.ie')

That works fine. Then I type the same but using a colon instead:

window:open('http://google.ie')

Why does using a : still work and execute the open function?

like image 944
Nope Avatar asked Mar 06 '14 14:03

Nope


1 Answers

The : makes window into a label rather than a variable:

window:
    open('...');

continue window;

And, since window is the global object in browsers, open() is a global function and can be directly referenced with or without it.

// both work
window.open('...');
open('...');

But, it's not a complete replacement for all objects and their properties:

var o = { foo: 'bar' };

o:foo // ReferenceError: foo is not defined
like image 87
Jonathan Lonowski Avatar answered Oct 20 '22 01:10

Jonathan Lonowski