On Wed, Jun 18, 2014 at 1:07 PM, Boris Zbarsky <[email protected]> wrote:
> On 6/18/14, 11:39 AM, Erik Arvidsson wrote:
>
>> This also fits how @@create works for DOM, where the creation of the
>> instance would set up the internal DOM wrapper pointer, never exposing a
>> non initialized DOM object to user code.
>>
>
> Note that in that setup it's impossible to introduce an HTMLElement
> constructor like this:
>
> var el = new HTMLElement("iframe");
>
This particular one can be done because if the constructor returns an
object that is used instead.
function HTMLElement(tagName = undefined) {
if (tagName === undefined) throw ...
var ctor = lookupConstructor(tagName);
return new ctor;
}
> because the @@create doesn't have the tag name available to create the
> right sort of object...
>
But the constructor is able to return any object it want, basically making
the constructor into a factory method.
This is an ugly pattern so it is discouraged but it does give you some
leeway when you need to support strange things.
--
erik
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss