extends with functions (was: Re: <| with function RHS is brittle)

# Herby Vojčík (14 years ago)

Herby Vojčík wrote:

Hello,

I now realized that I had a mistake in my mental model and that the difference is smaller than I thought. Whatever LHS is, it always behaves the same: it is set as a {[Prototype]] of the RHS. Putting RHS.prototype into LHS.prototype is pure "addon". Seeing it this way, it is ok.

Even when it is only "addon", it is in fact different behaviour. It would be nice if

x <| whatever-blueprint

could be defined so that object is created from whatever-blueprint and its [[Prototype]] is set to x. Even if RHS is function expression (or whatever in the future).

I'd suggest that setting parallel constructor/prototype hierarchy (very nice thing which should definitely be in the language), should be provided by different means. namely by class-specific keyword extends.

const Fox = function (...) extends Animal { ... } // expression

function Fox (...) extends Animal { ... } // declaration

This could kill two bird in one stone: <| could have consistent prototypal semantics all over, and doing class-like double hierarchy would be done with well-known class-domain keyword.

What do you think?