ecmascript 6 - How to dynamically create static method in JavaScript? -
if have this:
class math { static add(a, b) { return + b } } and want turn into:
class math { static add(a, b) { return + b } static subtract(a, b) { return - b } } is there way dynamically? eg.
class math { static add(a, b) { return a+b } } math.extend({ subtract: function(a, b) { return a-b } }) math.subtract(1,1) // 0
static methods nothing methods on constructor. need assign methods math:
object.assign(math, { subtract(a, b) { return - b } });
Comments
Post a Comment