3 ms·
Quick point of clarification. The post says: > As it turns out that isn’t entirely true since coffeescript > is a class based object oriented language
by jashkenas 15y ago
Quick point of clarification. The post says:
> As it turns out that isn’t entirely true since coffeescript
> is a class based object oriented language and javascript is
> prototype based. This was actually a mark against
> coffeescript for me since part of my desire to learn
> javascript was to dally in prototype based OOP.
CoffeeScript is prototype based to the precise same extent that JavaScript is. The "class" keyword is just sugar for JavaScript's constructor function + prototype chain combination. To mangle Shakespeare:
What's in a name? That which we call a class by any other name would smell as sweet.
Call it a prototype if you like -- it's the same thing in code.
- nuclearsandwich 15y agothanks Jeremy, do you mind if I insert your comment in the main body of my post? I am still a student of computer science and in my university's Java encapsulated worldview they've not discussed the finer points of non class-based OOP. I will do more research on the subject.
- jashkenas 15y agoGo for it. In a nutshell: An object is a unit of code and data that can be treated as a distinct entity. Classes and prototypes are both way to make objects. With a prototype, you start with an actual object as an example, and make more objects just like it. With a class, you start with the abstract set of properties that describe a type of object, and make more objects from that blueprint. Think of it as the Platonic ideal of a thing (the class), versus the canonical example of a thing (the prototype). To get specific: The idea of Bicycle, versus my blue bike with red streamers. Both can be used to make more bikes, in JavaScript. newBike = new Bicycle newBike = Object.create(myBlueBike)
- nuclearsandwich 15y agoAwesome. Thanks for that. I've always enjoyed the link between Platonic forms and object Classes. ahhhphilosophy.jpg