Why is the google homepage (0, obj.func) (args) used?

Sometimes I looked at js with the google.com homepage and found that they usually use the syntax (0, obj.func)(args) . Here are excerpts from the script:

  var _ = _ || {}; (function (_) { var window = this; try { _.mb = function (a) { return (0, window.decodeURIComponent)(a.replace(/\+/g, " ")) }; _.zg = function (a, b) { for (var c = a.length ? a.split("&") : [], d = 0; d < c.length; d++) { var e = c[d]; if ((0, _.Ag)(e) == b) return (c = /=(.*)$/.exec(e)) ? (0, _.mb)(c[1]) : null } return null }; _.Ag = function (a) { return (a = /^(.+?)(?:=|$)/.exec(a)) ? (0, _.mb)(a[1]) : null }; var Cg = function (a, b) { var c = a.indexOf("?"); return 0 > c ? null : (0, _.zg)(a.substring(c + 1), b) }; // Note var Cg called with no 0 var oca = function (a) { this.A = Cg(a, "mods"); this.B = Cg(a, "ver") }; } catch (e) {} })(_); 

Why add 0?

+20
javascript
Oct 23 '13 at 7:36
source share
1 answer

This makes an indirect call .

This ensures that the context in the called function is global. This may be useful in the interior.

Example:

 var a = { b: function(){ console.log(this); }, c1: function(){ this.b(); }, c2: function(){ (0, this.b)(); } } a.c1(); // logs a a.c2(); // logs window 
+33
Oct 23 '13 at 7:48
source share