top | item 13816308

(no title)

voyou | 9 years ago

TBH, I think the main difficulty is caused by people claiming there's some huge difference between prototype based and class based OO. There isn't, really (at least, not if you're comparing JavaScript and other widely used dynamic OO languages; prototype-based languages which emphasise copying, rather than delegation, are a bit more different).

In both cases, you can share behaviour between objects by putting that behaviour in another object and attaching it in a special way to the objects that should have similar behaviour - in JavaScript it's called __proto__, in Python it's called __class__, etc. Python (and Ruby, Smalltalk, and others) introduce an additional "meta" level of shared behaviour between all these class objects, whereas JavaScript (and Self) don't, but that's a comparatively technical implementation detail. Most languages other than JavaScript are include slightly more language-level support for one particular pattern of using this shared behaviour, which gives users of these languages a strong hint as to how to use these capabilities.

The addition of a class keyword to JavaScript is good because it emphasises what JavaScript shares with other dynamic OO languages.

discuss

order

chickenfries|9 years ago

Exactly. I don't get what secret superpowers I'm supposed to be gaining by using prototype OO over classes. One of them is just more familiar to the vast majority of programmers.