Why we need to clean up __proto__

David Bruant bruant.d at gmail.com
Thu Dec 29 04:58:15 PST 2011


Le 29/12/2011 03:04, Mark S. Miller a écrit :
> Darn. I completely missed that. No easy fix comes to mind. Suggestions?
I think '__proto__' in object literals should work like any property.
The ES.next proto operator [1] creates a standard alternative to using
__proto__ in object literal.
As the proposal says:
-----
Replace:
  var o = {
       __proto__ : myProto,
       a:0,
       b: function () {}
  }

With:
  var o = myProto <| {
       a:0,
       b: function () {}
  }
-----

__proto__ would then act like a regular property (shadowing the one on
the Object.prototype, very much like if it had been added with
Object.defineProperty). The ability to later change the prototype is not
lost as Lasse suggested.

I don't know to what extent my suggestion would break exisiting scripts.
Neither do I know whether breaking existing __proto__-using scripts is a
good or a bad thing.
If in some browsers it breaks something, browsers, when changing
__proto__ semantics could issue a warning in their console ("you're
using __proto__ in object literals and we have changed its semantics...").

David

[1] http://wiki.ecmascript.org/doku.php?id=harmony:proto_operator

>
>
> On Wed, Dec 28, 2011 at 6:01 PM, Allen Wirfs-Brock
> <allen at wirfs-brock.com <mailto:allen at wirfs-brock.com>> wrote:
>
>
>     On Dec 28, 2011, at 5:36 PM, Mark S. Miller wrote:
>
>     >
>     >
>     > Comments on this proposal appreciated.
>     >
>
>     Mark,
>
>     Your proposal doesn't address the occurrence of __proto__ as a
>     property name in an object literal
>
>     Allen
>
>
>
>
>
> -- 
>     Cheers,
>     --MarkM
>
>
> _______________________________________________
> 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/20111229/c3f5f846/attachment.html>


More information about the es-discuss mailing list