Promise() vs. new Promise()

Salvador de la Puente González salva at unoyunodiez.com
Thu Aug 21 00:22:45 PDT 2014


The only problem I see here is you can not emulate completely `new` with
ES. Why Promise add some internal slots when called with new and it does
not make the same when writing `var p = Object.create(Promise.prototype);
Promise.call(p, fn);`?


On Thu, Aug 21, 2014 at 5:18 AM, Andrea Giammarchi <
andrea.giammarchi at gmail.com> wrote:

> To this I'd like to add that in ES6 you don't need to explicitly invoke
> inherited class constructor but rather use `super`
>
> True is that this `new` story makes Mixins like constructors more
> difficult to use as classes becuase these cannot be invoked via `.call` or
> `.apply` directly and requires a very boring `init()` like method.
>
> Although there's nothing for mixins or their initialization in ES6 so it's
> OKish ...
>
> Last, but not least, since you use instanceof, I'd like to underline in
> ES5 capable browser you have another pattern.
>
> ```js
> function SelfInstance() {'use strict';
>   return this || new SelfInstance;
> }
> ```
>
> no need to use the `instanceof` check when `this` could be undefined ^_^
>
> Regards
>
>
>
>
> On Wed, Aug 20, 2014 at 5:55 PM, Alex Kocharin <alex at kocharin.ru> wrote:
>
>>
>> 20.08.2014, 19:18, "Claude Pache" <claude.pache at gmail.com>:
>> > Le 20 août 2014 à 16:56, Alex Kocharin <alex at kocharin.ru> a écrit :
>> >>  But... why?
>> >>
>> >>  I mean, every constructor can determine if it is called without `new`
>> (that "this instanceof" check on top of every other constructor). So `new`
>> keyword can really be removed from everywhere except in constructors
>> themselves.
>> >>
>> >>  Using `new` does create issues. For example, you can't write "new
>> require('something').Constructor(blah)", and I don't even remember how to
>> put brackets right.
>> >>
>> >>  Why make people use it?
>> >
>> > According to http://esdiscuss.org/notes/2013-07-25 (search for
>> "anti-pattern"), allowing constructors without `new` would break
>> subclassing.
>>
>> Still doesn't make much sense... This pattern (this instanceof ...)
>> breaks another pattern (BaseClass.call(this)). Why first one is deprecated,
>> not the second one?
>>
>> I mean, I was able to subclass such a class with prototype injection
>> without any issues, and it feels more natural in javascript after all.
>>
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140821/6698592c/attachment.html>


More information about the es-discuss mailing list