-2

I found the source code like this. I am familiar with javascript anonymous function though,

what is :?

For example

When I call createOverlays function with argument, how can I make it ?

I am googling around about : but unable to find good explanation.

I might not understand the basic javascript structure.

Please give some hint.

var World = {
    init: function initFn() {   
        this.createOverlays();
    },

    createOverlays: function createOverlaysFn() {
         // some function
    },
}

simply solved. I can pass the argument like this.

var World = {
    init: function initFn() {   
        this.createOverlays(1);
    },
    createOverlays: function createOverlaysFn(arg) {
         // some function
         console.log(arg) //show 1
    },
}
whitebear
  • 7,388
  • 15
  • 69
  • 143
  • 2
    Haven't you heard about [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects) – Tushar Dec 02 '15 at 03:49
  • Instead of Googling, just read some basic JS tutorials. What does "archive" mean? –  Dec 02 '15 at 04:02
  • Thank you for comment. I found I can pass the argument like this. I should learn more about Object. thanks a lot. – whitebear Dec 02 '15 at 19:25

1 Answers1

1

The : in this case creates a property on the object World. So the property createOverlays is being set to the function following it.

If you want to access it, you need to access the object first, and use the dot or bracket notation to access it:

// Dot Notation
World.createOverlays();

// Bracket Notation
World['createOverlays']();
TbWill4321
  • 8,098
  • 2
  • 21
  • 22