Proper way to dynamically add functions to ES6 classes
问题 I have a simple class with a single method exec(arg1,..,argn) and I want to have a number of alias methods which call exec with predefined argument values (e.g. exec_sync = exec.bind(this, true) ). The following does the trick: class Executor { constructor() { this.exec_sync = this.exec.bind(this, true); } exec(sync, cmd, args/* ... */) { // impl } } But I don't know if this is a good idea or if this is idiomatic to ES6. UDATE: In a real-life example I have two nested loops with respectively