On 10/13/2011 09:23 AM, John J Barton wrote:


On Thu, Oct 13, 2011 at 8:32 AM, Allen Wirfs-Brock <al...@wirfs-brock.com <mailto:al...@wirfs-brock.com>> wrote:

    ..

    My understanding of <| is that it sets the [[prototype]] property
    and nothing else. Consequently, I think that the semantics of
    "Array <| function(...){}" is to create a function with the
    prototype chain as follow:
    (anon function)  --> Array --> Function.prototype -->
    Object.prototype --> null
    And unless otherwise specified, (anon function).prototype is a
    fresh object inheriting from Object.prototype (not Array.prototype)

    that was the original idea but a couple of months ago the <| spec
    was updated:
     "If the LHS operand has a property named |prototype| and the RHS
    operand is a function expression then the [[Prototype]] of the
    function object is set to the LHS object and the |prototype|
    property of the new function is set to a new object whose
    [[Prototype]] is the value of the LHS’s |prototype| property."
    (http://wiki.ecmascript.org/doku.php?id=harmony:proto_operator )


For me this paragraph is a puzzle. A lot of the problem for me is "a property named prototype" vs [[Prototype]], two things with the same owner and same name to first order, but completely different in meaning. In addition we have function 'expression', function 'object', 'new' function and 'new' object.

I find the [[prototype]] prototype language confusing. Sometimes it helps me to understand the spec by (temporarily) replacing all occurrences of [[prototype]] with [[inherits from]]. Then that paragraph reads:

"If the LHS operand has a property named |prototype| and the RHS operand is a function expression then the [[inherits from]] of the function object is set to the LHS object and the |prototype| property of the new function is set to a new object whose [[inherits from]] is the value of the LHS’s |prototype| property."

In pseudo code...

if (LHS.hasOwnProperty("prototype")) {
LHS.prototype <-- inherits from -- RHS.prototype (a new object created by <| ) LHS <-- inherits from -- RHS (a new function created by <| and the expression to the right of <| )
}

Or in more detail and browser specific pseudo code...

LHS = make_object_from_source_code_string(..left of <|..);
if (is_source_code_string_a_function_expression(..right of <|..)) {
    if (LHS.hasOwnProperty("prototype")) {
        RHS = make_function_from_source_code_string(..right of <|..);
        RHS.prototype = {...};
        RHS.prototype.__proto__ = LHS.prototype;
        RHS.__proto__ = LHS;
    }
}

And so "var SubClassConstructor = ClassConstructor <| function () {}" will maintain the pseudo-clasical-oo-facade that exists in ES currently.

Jay

_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to