8 ms·
Understanding Javascript OOP
- deleted 14y ago[deleted]
- joubert 14y agoThe ES6 draft spec now includes the (maximally minimal) class spec that was hashed out at the July TC 39 meeting. You can read the spec here: http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts http://wiki.ecmascript.org/doku.php?id=harmony:specification... and see some examples here: http://wiki.ecmascript.org/doku.php?id=strawman:maximally_minimal_classes http://wiki.ecmascript.org/doku.php?id=strawman:maximally_mi... There's a cool project, Harmonizr (https://github.com/jdiamond/harmonizr https://github.com/jdiamond/harmonizr) which transpiles ES6 to ES5, which you can leverage to start using classes, modules, arrow syntax, etc. now. Demo: http://jdiamond.github.com/harmonizr/demo/demo.html http://jdiamond.github.com/harmonizr/demo/demo.html
- hayksaakian 14y agothank the lord, i can't imagine something as ubiquitous as javascript still has no syntactically intuitive class system
- darkstalker 14y agoThe MooTools library implements declarative class syntax for regular javascript: http://mootools.net/docs/core/Class/Class http://mootools.net/docs/core/Class/Class
- elehack 14y agoWhy not? Classes are just one implementation/realization of OOP. They're the most common, to be sure, but they're by no means the only way to do objects, nor are they necessarily the best. “There is more to OOP, Horatio, than is dreamt of in your philosophy.”
- jarek-foksa 14y agoFrom my read of the proposal ES6 classes feel more like syntactic sugar for the flawed concept of new/constructor/obj.prototype, you still have to mess with obj.prototype to achieve some tasks (e.g. define non-enumerable property). I would stay away from it and just use plain objects with Object.create().
- zwieback 14y agoThanks for that. In my mind I've been calling C++, C#, etc. "class-based" programming since the design/programming phase is really focussed on classes. I've not much experience with prototype-based programming other than the occasional blurb. This is a nice intro.
- deleted 14y ago[deleted]
- protomyth 14y agoIf you have the time, go look at an explanation of NewtonScript then Self. NewtonScript takes the concepts of Self and created a pretty nice little language that is a little more accessible than Self (unless you know Smalltalk, then go with Self first). I like prototype-based languages and really wish that NewtonScript had a little better syntax. On the other hand, I have never been fond of Javascript and don't know why. http://selflanguage.org http://selflanguage.org http://en.wikipedia.org/wiki/NewtonScript http://en.wikipedia.org/wiki/NewtonScript and http://waltersmith.us/wp-content/uploads/2005/12/OOPSLA95.pdf http://waltersmith.us/wp-content/uploads/2005/12/OOPSLA95.pd...
- stan_rogers 14y agoCognitive dissonance, likely. It doesn't look like what it is, no matter which part of it you're using at the time. Its selfish features aren't Self, its speech impediment isn't really a Lisp, its coffee-flavouring isn't Java... No matter which door you open, you get a preliminary sense of déja vu, then realise that you haven't actually been there before; it's just something that reminds you of something else. It takes a while to settle into JS mode, where the language is just what it is, and not "sort of like X, but completely different". (Once I'm there, I like to stay there—but there's always something else to do that drags me into another language, and when I come back, I experience the same cycle process again.)
- ExpiredLink 14y ago> This is a nice intro. ... with a misleading title since it's about "Prototypical inheritance".
- SwearWord 14y agoThis is the best js tutorial I've seen in a while
- migfromparis 14y agoReally good tutorial. I enjoyed reading it.
- rbellio 14y agoI was just looking for something like this last week, this is a great tutorial, thanks for posting it up here. When Anders was discussing the new TypeScript release, he was mentioning how it more clearly mimicked the ES6 specification. Looking at some of the examples posted by joubert, you can see the similarities. TypeScript transpiles down to ES5 much like Harmonizr does as well. Very interesting stuff.
- andyl 14y agoGreat tutorial - thank you.
- grandalf 14y agoThis is superb.
- deleted 14y ago[deleted]
- justinj 14y agoor, for a shorter read, try http://yehudakatz.com/2011/08/12/understanding-prototypes-in-javascript/ http://yehudakatz.com/2011/08/12/understanding-prototypes-in...
- jasonkostempski 14y agoI thought I had read it all at this point. I really like the deep dive into Object. No one ever goes beyond Object.create() and that's usually just as an example of how not to create new objects :)
- jroseattle 14y agovery well done.