Property vs Behavior inheritance

John J Barton johnjbarton at
Thu Dec 15 11:42:42 PST 2011

On Thu, Dec 15, 2011 at 9:51 AM, Axel Rauschmayer <axel at> wrote:

> A naming convention is not enough? Right now that works reasonably well
> for “functions versus constructors”.

My assessment differs: "The capital-letter constructor solution works well
for a single level of inheritance in simple systems"

> With object exemplars, you have:
>     var jane = new Person("Jane");
>     var Employee = Person <| { ... };

(Since I guess only long time readers of this newsgroup could understand
what you write above, let me give a capsule summary:
Employee becomes an object with a .prototype property referring to an
object with properties of the RHS and a [[Prototype]] of the LHS.
Employee.prototype to inherits from Person.prototype and adds properties in

What constructor is invoked if I write:
  var jack = new Employee(...);

Let's just make your example slightly more real. There is nothing to help
us avoid this kind of pothole:
   var Employee = Person <| { hoursPerWeek: 40  };
   var Contractor = Employee <| { ... };
   var PartTimer = Employee <| {...};
The failure mode derives from using object literals for both objects and
classes. Experience, review, or debugging have to save us. (I guess we
can't require the operands of <| to be capitalized and the RHS to have only
functions?).  I don't think we make this error in class-based languages.

The <| operation solves the same problem that seflish solves: behavior
inheritance; they both use object literals (optional in selfish); neither
address the data-property specification problem nor the data-property
initialization problem.

> I don’t think one would make the mistake of extending jane. Ironically, a
> class-based mindset works well here and does not lead you astray.

Indeed, and perhaps that is my point. Does a classless solution make sense
if in fact you have to rigorously apply extra-lingual class-based reasoning
to succeed?

To be clear, I'm a JS fan; I don't want it to become Java. Nevertheless our
current inheritance system is pretty silly.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list