Why does google main page use (0, obj.func)(args) syntax?

This makes an indirect call.

This ensures the context, in the called function, is the global one. This might be useful in an internal scope.

Example :

var a = {
  b: function(){
     console.log(this);    
  },
  c1: function(){
     this.b(); 
  },
  c2: function(){
     (0, this.b)(); 
  },
  c3: function(){
     (this.b)(); 
  }
}
a.c1(); // logs a
a.c2(); // logs window
a.c3(); // logs a

Leave a Comment