Promise() vs. new Promise()

Allen Wirfs-Brock allen at wirfs-brock.com
Thu Aug 21 09:28:21 PDT 2014


On Aug 20, 2014, at 7:30 PM, Andrea Giammarchi wrote:

> I like the `Function.prototype.new` hint but unless it's an implicitly
> self bound method you still cannot easily pass it around as callback
> for a map without binding it all over.
> 
> `arr.map(MyClass.new)` without needing to explicitly bind it each time
> is needed/used would be an exception, but probably a good one.

true, but you can write:

arr.map((...a)=>new Map(...a));

or define:

Object.assign(Function.prototype, {
   get asFactory() {return (...args)=>new this(...args)}
}

so you can say:

arr.map(MyClass.asFactory)

Allen


More information about the es-discuss mailing list