prototype for operator proposal for review

Bob Nystrom rnystrom at google.com
Wed May 18 11:30:00 PDT 2011


What about making the operator go in the other direction, like so:

{a:1,b:2} |> MyObject.prototype

[0,1,2,3,4,5] |> appBehavior

Array.create=function(proto,props) {
  return Object.defineProperties([ ] |> proto, props)
};

let f = function () {} |> EnhancedFunctionPrototype

var p = /[a-m][3-7]/ |> newRegExpMethods

var  o = {
     a:0,
     b: function () {}
} |> myProto


The mnemonic is preserved, but I find this a little more natural to read. In
particular:

1. The data specific to this instance appears first.
2. The "|>" can be read as "extends" instead of "is extended by".
3. The objects are ordered from left-to-right in the order that properties
on them are looked up. Given "foo |> bar" we'll look for a property on "foo"
then "bar".

Personally, I don't have a strong opinion since I don't think I'd use this
much regardless of syntax, but I wanted to put this out there.

- bob

On Wed, May 18, 2011 at 10:34 AM, Brendan Eich <brendan at mozilla.com> wrote:

> On May 18, 2011, at 10:30 AM, Allen Wirfs-Brock wrote:
>
> > On May 18, 2011, at 9:52 AM, Brendan Eich wrote:
> >
> >> On May 18, 2011, at 9:51 AM, Brendan Eich wrote:
> >>
> >>> On May 18, 2011, at 9:47 AM, Allen Wirfs-Brock wrote:
> >>>
> >>>> In the end, these are just symbols  and JS programmer are just going
> to have to learn their meaning. Existing conventions, if they exist, and
> analogous do impact initial learnability but in the long run I don't know if
> it makes much a difference as long as they aren't prone to keyboarding
> hazards.
> >>>
> >>> The precedents matter a bit, even if we try to create a new idiom. The
> problem is < not | (although doesn't that look too light in Helvetica on
> either side?).
> >>
> >> I don't think :> works, as you say. It looks like crap, frankly, in too
> many fonts. However, does |> not work?
> >>
> >> /be
> >
> > |> could work but I think we agree that the object literal (or array or
> function for that matter) really needs to be on the right for readability.
> In that case |> seems to be point ingin the wrong direction from any of the
> perspectives: UML generalization, [[Prototype]] pointer direction, type
> specialization...
>
> Gotcha, I'm sold. It's an idiom.
>
> I will go play TMBG "Particle Man", the "Triangle Man" verse.
>
> /be
>
> _______________________________________________
> 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/20110518/c84ce393/attachment.html>


More information about the es-discuss mailing list