2

Here is the code sample I have a question about:

var javascriptObject = {
   functionName1: function functionName2() {

   }
}

I understand the concept of an object in the javascript. I understand everything in the code sample except the functionName2 what is its purpose?

And I saw the code in the real life projects:

init: function init() {
        init._base.call(this);
}

The code above does not work if I get rid from the second init. What does that second function name mean in javascript?

yrslvrtfmv
  • 75
  • 7

1 Answers1

1

Object in JS are just name value pairs nothing more

var javascriptObject = {
   functionName1: function functionName2() {

   }
}

So what your doing is having a object which has a name of functionName1 which has the value of

function functionName2() {}

The name of the function stored in this value is functionName2 but this also could be omitted since it is not necessary to invoke the function.

For example you could run the function without the functionName2

var javascriptObject = {
   functionName1: function () {
      return 5;
   }
};


var bar = javascriptObject.functionName1();
console.log(bar);
Willem van der Veen
  • 33,665
  • 16
  • 190
  • 155