27 ms·
I don't mean to be argumentative (being argumentative on HN is so passé), but what you just quoted is so full of shit that I feel like someone is obligated to c
by jashkenas 12y ago
I don't mean to be argumentative (being argumentative on HN is so passé), but what you just quoted is so full of shit that I feel like someone is obligated to comment.
In the prototypal model — as it exists in JavaScript — you do do all of that. You make a series of prototypes that you intend to use in your application, and those prototypes (or classes), serve as the effective taxonomy for many of the objects you're making in your app.
Classes in ES6 are prototypes. They don't lock you into any such Java-esque paradigm unless you're going to be willfully ignorant about them.
Please don't repeat baloney just because Crockford said it.
---
For example, to be concrete:
class Crockford {
speechify() {
return "...you're going to get the taxonomy wrong. It’s inevitable.";
}
}
A class. A terrible, inflexible, prototype-destroying, paradigm-locking-in, JavaScript class. Eww, gross.
But wait! What's this?
Crockford.prototype.speechify = function() {
return "...the shape of an object can change at any instant, because \
someone can fiddle with the prototype.";
};
You can have your classical cake and eat prototypal cookies too. Because in any decent dynamic language, the two concepts are synonymous.
- greggman 12y agoIt's not baloney IMO. As someone who's coded C since the 80s and C++ since the 90s I find JavaScript massively freeing. In C++ (and similar classical languages) in order to be able to pass in different implementations of a class you need to create a base class or interface. You don't need to do this in JavaScript. In JavaScript you can build objects on the fly. In fact he goes on to say > so I used to think that the important thing in JavaScript was prototypal inheritance I now think it is Class Free object oriented programing. I think that is JavaScript’s gift to humanity. That’s the thing that makes it a really interesting important language, is that it did that. That we can use functions in order to create objects and it simple and elegant and powerful and fast... And it's true. Look at the mocking libraries for JavaScript. They're sooooooooo much easier to write than anything for classical languages because it's so easy to do in JavaScript. In my own experience I have a mutli-user networking system written in JavaScript and a library in C#. To reimplement the same things in JavaScript in C# is a huge amount of code bloat. I have to make classes and meta classes and all kinds of other indirection just so I can make an Event system that is generic. In JavaScript that's 2 or 3 lines That we don't actually need all the structure to get shit done is what people are finally coming to realize. The problem with 'class' in ES6 is that it will prevent people from learning this new, easier, faster, simpler way of working because instead they just bring the classical baggage to JavaScript. That's in fact what most programmers from classical languages do. It's what I did for years until I started actually grokking JavaScript. ES6 "class" will only make it take longer for people to actually get pass their old ways.
- Touche 12y agoI think you're confusing this new Chrome-only thing with ES6 classes that just saves you from using a library to create constructor/prototype objects. In ES6 "class" is just a keyword that makes it easy to contruct objects that are very typical in day-to-day JS. Inheritance is already a thing that happens.
- greggman 12y agoI'm not. See above, "class free object oriented programming". You don't need prototypical inheritance to have inheritance in JavaScript. Crockford gives examples. You don't need the "class" keyword. All it's going to do is steer people in the wrong direction.
- Touche 12y agoCan you give an example of inheritance without prototypes in javascript?
- greggman 12y agofrom D.C. function base(spec) { var that = {}, member, method = function() { // spec, member, method }; that.method = method; return that; } function derived(spec) { var that = base(spec), member, method = function() { // spec, member, method }; that.method = method; return that; } I'd suggest you watch the talk linked above for this stuff in context.
- Touche 12y agoThat is not inheritance. `instanceof` doesn't work. There would be no way to know that an object from derive dis of the type of base. That's also very memory inefficient. The method function gets made for every instance. With prototypes there would be only 1 function in memory. This stuff matters at scale.