2
這段代碼來自AngularJS源代碼,它有很多這種'函數返回函數'樣式代碼。爲什麼在Javascript中使用這種語法(從函數返回函數)
function locationGetterSetter(property, preprocess) {
return function(value) {
if (isUndefined(value))
return this[property];
this[property] = preprocess(value);
this.$$compose();
return this;
};
}
,這是否有過只是有額外的參數,如這樣的「常規」的功能是什麼advatanges -
function locationGetterSetter(property, preprocess, value) {
if (isUndefined(value))
return this[property];
this[property] = preprocess(value);
this.$$compose();
return this;
}
它基本上是咖喱。 –
柯里化帶來的好處是什麼? – csss
您不必每次都傳遞不變的參數。 –