*blog... kind of... *rss 



JavaScript: The Good Parts
Today neave was sharing this interesting talk over twitter. I wish I would have seen it before... now I'll need to go back and fix most of the JavaScript I've written :S



20 comments written so far...

You should read "the book" too. It's a real eye opener if you haven't had your eyes opened yet. Especially the way prototypal inheritance (nothing to do with the lib) and closures work.
Ok, I'll put it on the list :D
I recommend watching all the Crockford's videos on the YUI theater: http://developer.yahoo.com/yui/theater/

The JavaScript Programming Language and Advanced JavaScript ones changed my mind.
Wohoo! These talks look really interesting! Thanks a lot!
loved it, and i feel the same way about my javascript too. :}

also shed some light on some of the ideas in actionscript i dig so much too.
JS is still a ugly hack of a language. Hell, I'd rather go back and program in Lingo again. JS is the VHS to Actionscript's Betamax -- the better tech doesn't always win out.
His POV is valuable but I'd encourage checking this out too, before you rewrite all your JS... (counterpoint): http://www.bolinfest.com/javascript/inheritance.php
Yeah, I realised that his method didn't allowed "instanceof" to be used.

But stuff like putting the brackets on the same line and how to make private variables was something I didn't know. In the end, this is the pattern I'm using most of the times:

http://gist.github.com/396146
I've sort of mapped off of this template, which is pretty much the same (meant to be easy to port directly to Closure, but written agnostically):

http://gist.github.com/434091

I'm not sure what this does (why it is needed) in your sample:

NAMESPACE.Object.prototype.constructor = NAMESPACE.Object;
That basically extends the object. In my sample Particle extends Object3D so Particle will get all the properties and methods from Object3D.
Right, ehr I thought ObjA.prototype = new ObjB(); already did that (copied the prototype). Whereas ObjA.prototype.constructor = ObjA; -- I don't get what that does (seems like it would do nothing?!). I guess I need to go read what Object.prototype.constructor specifically does. Sorry to flood your comment stream __
By doing ObjA.prototype = new ObjB() you're inheriting all the variables and methods and that counts ObjB constructor. So if you do new ObjA() you won't be executing ObjA constructor but ObjB instead. By assigning the constructor back you're getting the desired behaviour.
%20AND%201=1
%20AND%201=2
AND 1=1/*
AND 1=2/*
' AND '1'='1
' AND '1'='2
' AND 1=1/*
' AND 1=2/*

Have your say!



Name:

Website:

Comment: