flâneur — a map of the web's best reading

Constructors Considered Mildly Confusing

zeekat.nl · saved by 1 readers

Consider this quote from Flanagan 2006, page 111 that came up in a comp.lang.javascript question in january 2008: In javascript, every object has a constructor property that refers to the constructor function that initializes the object. Sounds nice: it makes constructors sound static like classes in Java. Even the new Constructor() syntax looks like it. And it seems true: But life isn’t that simple: Javascript1 objects are simply bags of named properties that you can read and set. Javascript does not have classes. Functions in javascript are first-class objects. Methods in javascript are just properties that are functions. The prototype of an object is an internal property that I’ll refer to here as {Prototype}. In other words, obj.prototype is in general not the obj’s {Prototype}. The standard does not provide any way to retrieve the {Prototype} property from an object. Javascript objects can delegate properties to their {Prototype} and their {Prototype} can do the same; all the way

Explore this link on the map →

saved by