Open dlrandy opened 5 years ago
function curryN(fn){
var len = fn.length;
var args = [];
function _cur(){
var l = arguments.length;
if(l === 0){
return _cur;
}
var i = 0;
while(l--){
args.push(arguments[i++]);
}
len = len - i;
if(len > 0){
return _cur;
} else {
return fn.apply(null, args);
}
}
return _cur;
}
function t(d, b, c){
return d + b + c;
}
var a = curryN(t);
console.log(a(1,2)(6))
ES7的装饰器是一个返回function的表达式(意思就是要么本身是函数要么返回函数),修饰属性的时候接受target, name, propertyDescriptor作为参数;修饰类的时候接受constructor作为target
装饰器一般是用于透明的包装一些东西的函数,加一些额外的功能
本质是Object.definePropertyDescriptor
ES2016 Decorators work on property descriptors and classes Leading decorators must be attached to a class declaration (6:0)
https://medium.com/google-developers/exploring-es7-decorators-76ecb65fb841