Search code examples
javascriptjavascript-objectsnotation

using dot notation with more than one in javascript syntax



Could you please explain whats the mean of
first[dot]second like declaration in javascript rules

first.second = (function () {
    //...
})();

Solution

  • it means first is an object and second is a property of that object.

    it can be defined as follows too;

    var first = {};// {} -is JS object notation
    first.second = function(){
       alert('test');
    };
    
    //or
    var first = {
      second : function(){
         alert('test');
      }
    };
    
    
    //invoke the function
    first.second();// prompt alert message
    

    simple documentation