Hacker News new | past | comments | ask | show | jobs | submit login

I know it's not a hash table. That's the whole criticism anyway because I needed those features. It's pretty stupid that I had to Google for a proper hash table library when something as fundamental as this should be builtin.

Insanely powerful prototypal behavior? I haven't seen anything that I can't already do with Python's or Ruby's object models, but with much simpler syntax. Inheritance in Javascript is a mess, you have to manually write code to copy over the parent class's prototype to the child class, which is why every Javascript framework invents its own wrapper syntax for defining classes.




Inheritance in JavaScript isn't "a mess", it's a paradigm you don't understand[1]. Objects in JavaScript don't have "classes", they have prototypes, so if you want class-like behavior, of course you'll have to implement that yourself. Just like if I want to make key access on a dict fall through to another dict if the key isn't present in Python, I'll have to implement that myself. You may think that's silly, but in a prototypal language that is fundamental behavior.

The `new` keyword was intended to provide the appearance of classes (Java classes, specifically) to make prototypal inheritance less scary to users such as yourself coming from a class-based background, but it's a scam— it creates an object with a prototype, not an instance of a class, and as you're aware it has only caused more confusion about how object inheritance in JS really works.

I find the distaste that new developers have for `__proto__` a little analogous to an inexperienced front-end-only Lisp developer who likes parts of the language, but thinks the whole thing would make more sense without `eval` confusing things at runtime. They're not wrong, exactly, they just misunderstand something fundamental about the way the language actually works. The object prototype is there, it's mutable, and that should be exposed. Ignoring it won't make it go away.

So I'm not surprised you haven't seen a use case for prototypal inheritance, just like that guy hasn't seen a use case for `eval`. You're not going to because you're not looking; you're thinking of objects in JS as having classes, and that's just a fundamental misunderstanding.

For what it's worth, I only write CoffeeScript, which makes everything you think is a hassle in JS easy. In particular, the `class` keyword which has a much prettier, more traditional-seeming syntax to build constructors. But it's a highly leaky abstraction— if you don't understand that what it's compiling to is a function that creates a constructor and sets properties on its `.prototype` one at a time, you will be very confused by the more complex behavior. On the other hand, if you do understand what's going on behind the scenes, it allows for powerful metaprogramming, since you can call methods of the "parent class" or even the prototype itself during the definition.

[1] http://en.wikipedia.org/wiki/Prototype-based_programming


I understand the paradigm, and I think it's a mess compared to good old OO. I don't want prototypes. With Ruby and Python's OO, I can do everything the prototypal paradigm can, without any of the syntactical insanity, so the argument of prototyping being powerful doesn't hold up.

And yes I do think CoffeeScript is saner.




Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: