@@new
Erik Arvidsson
erik.arvidsson at gmail.com
Wed Jun 18 10:58:08 PDT 2014
On Wed, Jun 18, 2014 at 1:07 PM, Boris Zbarsky <bzbarsky at mit.edu> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140618/7c88e9e3/attachment.html>
More information about the es-discuss
mailing list