I would like to introduce a new function annotation (like @globalPrivate), @nakedConstructor. If this annotation is attached, the function becomes constructor, but it does not create_this automatically. The function need to return an object constructed from this function. Of course, the function need to care about new.target. This is very useful for Map, Set, and Promise constructors. These constructors do some JS specific things. For example, Set constructor takes an iterable object as its argument. And perform iteration and add values to the constructed object. If we can write it in JS, it is very nice... In the case of Promise, promise will invoke executor function, (new Promise(executor)). Currently, we always invoke this function in a tricky way. If we can implement the Promise constructor like the following, it is quite nice. @nakedConstructor function Promise(executor) { 'use strict'; var promise = @constructPromise(new.target); // some initialization... executor(promise.resolve, promise.reject); return promise; }
Sounds like a good idea to me.
(In reply to Yusuke Suzuki from comment #0) > I would like to introduce a new function annotation (like @globalPrivate), @nakedConstructor. > If this annotation is attached, the function becomes constructor, but it > does not create_this automatically. @nakedConstructor annotation was introduced in r249509. *** This bug has been marked as a duplicate of bug 200898 ***