有時我盯着google.com主頁提供的js,發現他們傾向於使用(0, obj.func)(args)
語法。這裏是腳本的摘錄:爲什麼Google主頁使用(0,obj.func)(args)語法?
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) {}
})(_);
爲什麼預先加0?
可能重複的[JavaScript語法(0,FN)(參數)(http://stackoverflow.com/questions/11541134/javascript-syntax-0-fnargs) – JJJ
喔,奇怪,我真的試圖谷歌這個,但沒有遇到這個問題... –
@Juhana但這次有一個實際的答案,不只是解釋逗號運算符;) – pawel