David Bruant wrote:
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.

Exactly, that was my concern, too.

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.

I would apply different, more cutting approach. Ditch the former completely. For functions, it is natural to inherit from functions.So that ultimately it leads to Function.prototype.

(Having jQuery) you can do $.extend(function(){}, x) <| function (...) {...} to achieve similar thing.

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)?

Well, I would definitely say this is so special that "make simple things simple, make hard things hard" is appropriate and no helper would be there for the user. He can do it by:

  var f = FunParent <| function (...) {...};
  f.prototype = Object.create(protoParent, { constructor: {
    value:f, writable:true, configurable:true
  }});

One answer could be that the 2 operators could be composed together.

And it works in line with ditching the proto-for-function syntax.

David

Herby
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to