es6 chain decorators

by shushanth pallegar

Babel + JSX

function decorateChain(target, name, descriptor) {
  const originalFn = descriptor.value;
  descriptor.value = (...args) => {
  console.log(...args);
  	originalFn.apply(target,args);
    return target;
  }
}

class Person {
  
  constructor(){
    this.name;
    this.age;
  }
  
  @decorateChain
  sayName(name) {
    this.name = name;
    console.log(this.name)
  }
  
  @decorateChain
  sayAge(age) {
    this.age = age;
  }
 
  @decorateChain
  alertName(){
  	alert(this.name);
  }
}

let p = new Person();
console.log(p.sayName('jeff').sayAge(40).alertName());