HNHacker News
TopNewBestAskShowJobs

jimmydo

125 karma · joined February 8, 2011

submissionscomments
jimmydo··on Amazon Cloud Drive and Amazon Cloud Player
It doesn't seem like they currently do this, but it would be great if Amazon applied file de-duplication (like Dropbox) to at least music files. If I'm trying to upload a song that Amazon already has on its own servers, it should just use that copy instead of uploading a new copy from my computer.
jimmydo··on Simple JavaScript Inheritance with Backbone
That was a really interesting talk--thanks for the link!

Something that initially confused me was that Eich's use of the term "prototypal" (a pattern for implementing class-based inheritance) was different from Douglas Crockford's use of it (an alternative to class-based inheritance - http://javascript.crockford.com/prototypal.html).

In case anyone else finds this useful, here's how I sorted it out:

- "class-based" & "prototype-based" inheritance (Crockford refers to them as "classical" & "prototypal" inheritance). Different styles of instantiating objects.

- "closure pattern" & "prototypal pattern" (aka "prototypal inheritance" in this context). Different techniques for implementing class-based inheritance.

jimmydo··on Simple JavaScript Inheritance with Backbone
The mostly likely reason is probably familiarity. Most languages use the 'new' operator to create new objects, so it seems natural to follow the same pattern when creating a JS API that will likely be consumed by people who come from other languages.

The main advantage of Douglas Crockford's power constructor pattern is that it allows truly private variables or functions. I used to be adamant that this was the right way to go (and I still appreciate the pattern), but then I found that just following the convention of prefixing private members with an underscore worked fine--most people understand that it means "private". My code also started to look a little neater. All of my instance members are actually tied to the 'this' context object, rather being spread between nested functions or local variables declared within the constructors, and public/privileged methods declared on the new object itself.

jimmydo··on Simple JavaScript Inheritance with Backbone
You're right! Fixed. Thanks for letting me know.
jimmydo··on Simple JavaScript Inheritance with Backbone
Yup, I agree. I recently submitted a pull request for changes I made to expose a primitive Base class in Backbone: https://github.com/documentcloud/backbone/pull/276
jimmydo··on Simple JavaScript Inheritance with Backbone
That's really what I liked the most about the Backbone implementation. It stays very close to the standard JS pattern--essentially mirroring what someone would do if they wanted to setup the prototype chain and attach methods manually.

It asks you to name the constructor method 'constructor' (when it could've easily been called something short like 'init' instead, for brevity). This corresponds well with the standard 'constructor' property available on each object, which points back to the constructor function that created the object.

The '__super__' property is also a nice convenience, without doing something "fancy" like wrapping each method with logic that temporarily injects a 'super' property into the current instance for the duration of a method call. Although that's definitely clever and convenient, I prefer the simplicity of using '__super__'.

jimmydo··on Simple JavaScript Inheritance with Backbone
CoffeeScript does have really nice syntax for OOP, but I think JavaScript deserves some lovin' too. Well-written JavaScript (such as Backbone) looks pretty beautiful. Another plus is that new devs (if you have to worry about that sort of thing) don't have to learn a new language.