javascript - How to recognize the function is the class constructor and how to call it as a function? -
i'm little bit confused class feature in es2016, though assumed syntax sugar creating classes, in comparison function , prototype , behaviour in cases different, in particular - classes can't called same functions , seems, there no way find out if function class constructor or simple function, without using tostring , /^class/ regexp . assume example: class foo { constructor () { this.name = 'foo'; } } function bar () { this.name = 'bar'; } function dosmth (anyarg) { if (typeof anyarg === 'function') { var obj = { someprop: 'qux' }; anyarg.call(obj); return obj; } // ... } dosmth(bar); dosmth(foo); // class constructor foo cannot invoked without 'new' is typeof 'function' , can't call function! nice. and here 2 questions: is there way can call foo constructor function same bar overriden this context? is there way can detect anyarg constructor of...