javascript - The new Operator -
is possible write javascript function follows (valid) typescript interface:
interface foo{ // constructor: new (): string; }
i.e. when called new operator returns string. e.g. following not work.
function foo(){ return "something"; } var x = new foo(); // x foo (and not string) whether or not :)
you should able do:
function foo(){ return new string("something"); } var x = new foo(); console.log(x);
you can return object, literals don't work. see here: what values can constructor return avoid returning this?
Comments
Post a Comment