The class operator: a bridge between object and function exemplers

Mark S. Miller erights at google.com
Mon Nov 14 17:18:50 PST 2011


On Mon, Nov 14, 2011 at 5:13 PM, Mark S. Miller <erights at google.com> wrote:

>
>     function [[GetClass]](x) {
>       while (true) {
>         const proto = Object.getPrototypeOf(x);
>         if (proto === null) { return null; /* or void 0? */ }
>         let result;
>         if (hasOwnProperty(proto, 'constructor') &&
>             (result = proto.constructor) &&
>             typeof result === 'function' &&
>             result.prototype === proto) {
>           return result;
>         }
>       }
>     }
>

Oops. Should be

    function [[GetClass]](x) {
      while (true) {
        x = Object.getPrototypeOf(x);
        if (x === null) { return null; /* or void 0? */ }
        let result;
        if (hasOwnProperty(x, 'constructor') &&
            (result = x.constructor) &&
            typeof result === 'function' &&
            result.prototype === x) {
          return result;
        }
      }
    }

-- 
    Cheers,
    --MarkM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20111114/5631c58d/attachment.html>


More information about the es-discuss mailing list