dlrandy / note-issues

2 stars 0 forks source link

ES7 Decorators #99

Open dlrandy opened 5 years ago

dlrandy commented 5 years ago

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

dlrandy commented 5 years ago

http://2ality.com/2015/03/es6-generators.html

dlrandy commented 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))

https://hackernoon.com/currying-in-js-d9ddc64f162e