Live data from Hacker News

Prototypes Are Not Classes

raganwald.com

11–20 of 46 posts

Re: Prototypes Are Not Classes

#11
Jesus, the language is called Smalltalk. Not SmallTalk.

Btw., in a typical language supporting prototypes, I would expect that prototypes are nothing special. Every object could be a prototype for others...

Re: Prototypes Are Not Classes

#12
post #8

Earlier quoted context omitted.

I'm not sure that's a good idea, because then they'd be made very sad by constructors, by prototypes being something completely different[0], by not having mixins[1], by single-inheritance, by dynamic inheritance[2], by the lack of blocks (and non-local returns), etc… Essentially, by javascript not being a very good Self. [0] IIRC in Self the prototype is the object you copy, objects linked through parent slots are e…

MI still sends shivers down my spine, having spent time in the C++. Just say no.

So C++ got multiple inheritance wrong... That doesn't mean it must be rejected in all cases.

Re: Prototypes Are Not Classes

#15
post #11

Jesus, the language is called Smalltalk. Not SmallTalk. Btw., in a typical language supporting prototypes, I would expect that prototypes are nothing special. Every object could be a prototype for others...

That's true in JavaScript - there's an Object.create() method, which creates new object with any other object set as prototype: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

There is a problem with accessing prototypes of objects, as they are not exposed to the user and only available through internal property __prototype__ (IIRC). And there's quite a bit of magic involved with constructor prototypes, which - again - makes it impossible to traverse prototype chain unless you create your objects yourself and store the references yourself.

So yeah, prototypes are nothing special in JS, but their API kind of sucks and could get better. Object.create is a step in the right direction IMO.

Re: Prototypes Are Not Classes

#16

Earlier quoted context omitted.

MI still sends shivers down my spine, having spent time in the C++. Just say no.

So C++ got multiple inheritance wrong... That doesn't mean it must be rejected in all cases.

What are the cases where MI is better than mix-ins or component architectures?

Re: Prototypes Are Not Classes

#17
post #11

Jesus, the language is called Smalltalk. Not SmallTalk. Btw., in a typical language supporting prototypes, I would expect that prototypes are nothing special. Every object could be a prototype for others...

That's true in JavaScript - there's an Object.create() method, which creates new object with any other object set as prototype: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... There is a problem with accessing prototypes of objects, as they are not exposed to the user and only available through internal property __prototype__ (IIRC). And there's quite a bit of magic involved with constructor prototype…

> There is a problem with accessing prototypes of objects, as they are not exposed to the user

Actually, Object.getPrototypeOf was added in ECMAScript 5.1. It's even supported by IE9.

> only available through internal property __prototype__ (IIRC)

It's an external property (the internal one is `[[Prototype]]`_, and is called `__proto__`. It's non-standard, although all modern browsers implement it (even IE11, but not IE10)

Re: Prototypes Are Not Classes

#18
post #8
post #5

I guess before learning JavaScript, developers need to be sent to a Self learning camp.

I'm not sure that's a good idea, because then they'd be made very sad by constructors, by prototypes being something completely different[0], by not having mixins[1], by single-inheritance, by dynamic inheritance[2], by the lack of blocks (and non-local returns), etc… Essentially, by javascript not being a very good Self. [0] IIRC in Self the prototype is the object you copy, objects linked through parent slots are e…

I think that the claims that "JavaScript is like Self" or that "JavaScript is like Scheme" are attempts to legitimize what really isn't a very good language to being with. I think that this is also done out of ignorance, to a large extent. People hear about Scheme and Self being held in high regard, hear about some very vague similarities with JavaScript, and then assume that JavaScript is somehow like Scheme and Self, even if they've never used Scheme or Self. The supposed similarities only extend to JavaScript supporting anonymous functions and closures (just like numerous other languages) in the case of Scheme, or merely just sharing some terminology with Self. So there isn't any real basis to these claims.

Re: Prototypes Are Not Classes

#19

Earlier quoted context omitted.

So C++ got multiple inheritance wrong... That doesn't mean it must be rejected in all cases.

What are the cases where MI is better than mix-ins or component architectures?

Maybe just in some corner cases.

However Eiffel, OCaml and Python MI implementations seem to be implemented in a more sane way.

Re: Prototypes Are Not Classes

#20
post #11

Jesus, the language is called Smalltalk. Not SmallTalk. Btw., in a typical language supporting prototypes, I would expect that prototypes are nothing special. Every object could be a prototype for others...

And weirdly, I often miss-spell JavaScript as "Javascript." No idea why.
Post reply on HN