Classes: suggestions for improvement

Axel Rauschmayer axel at rauschma.de
Tue Jun 14 15:00:29 PDT 2011


> JS uses "prototype" to mean two distinct things:
> 1) the object associated with a constructor function that's used as the prototypical instance of objects created by that constructor and
> 2) the object an object inherits from. (Self uses "parent" for the latter, which makes things less confusing.)

I would rephrase (1) as follows:
- The object associated with a constructor function that becomes the /prototype/ of all instances created by the constructor. That is, it is an object that all instances inherit from.

The term “prototypical instance” might convey the wrong image, as Point.prototype is more of a meta-instance.

But in general: point taken. I do like the idea to use “factory”, but “class” might be close enough to people’s expectations that it works. What I find complicated is that what would be a class in, say, Python, is two constructs in JavaScript: (1) the constructor produces and initializes instances, (2) the prototype contains shared data.

Axel

-- 
Dr. Axel Rauschmayer

axel at rauschma.de
twitter.com/rauschma

home: rauschma.de
blog: 2ality.com





More information about the es-discuss mailing list