(How) does proto operator distiguish between function and non-function in LHS?

David Bruant bruant.d at gmail.com
Sat Jan 28 10:25:57 PST 2012

Le 28/01/2012 09:28, Herby Vojčík a écrit :
> The proposal for <| cites these usage examples:
> - Setting the prototype of a function to something other than
> Function.prototype
>     let f = EnhancedFunctionPrototype <| function () {}
> - Parrallel constructor/instance prototype chains
>     let superclass = function () {};
>     //define a constructor method
>     superclass.new = function () {return (new this()).initialize()};
>     //define a instance method
>     superclass.prototype.initialize = function () {return this};
>     let subclass = superclass <| function () {};
>     ...
> Question: When RHS is function expression, does it distinguish if LHS
> is function to select one of the (different) behaviours from above?
The problem is that even if it did, it wouldn't be enough to say if the
intention of the programmer was the first case (enhanced function
prototype) or the second case (richer constructor), since a function on
the LHS could be used in both cases.

I have raised the concern already and am not sure I have received an
answer yet. I think 2 operators should be created. One for each case.

One question that could arise is: what if someone wants to build a
function with a particular constructor behavior and an enhanced
prototype (unrelated to the constructor it "inherits" from)?
One answer could be that the 2 operators could be composed together.


More information about the es-discuss mailing list