I’m back in the JavaScript trenches. I continue to be amazed at how flexible the language is - once you really dig into it. That’s the good news - but then comes the bad news.
I’ve grown very used to a number of the great features of Ruby. To be completely honest in a number of cases I didn’t really even think about them being there - because Rails uses them for incredibly great programmer outcomes. Now that I’m in JavaScript and they are missing - the sadness is ensuing.
An easy example of what I’m talking about:
person.name = “Bob Roberts”
person.name #Bob Roberts
On the Ruby side that can actually be implemented as a set of methods on the object.
class Person
def name()
return(@name)
end
def name=(name)
@name = name
end
end
Ruby hides the method part from you - which is nice. If you wanted to get a little crazy you could do it with a method missing call (This is not the way to do it but I’m making a point here - stick with me).
class Person
def method_mission(m, *args)
if m == "name"
if args[0]
@name = args[0]
return true
else
return(@name)
end
end
end
Not pretty - but very very powerful. I’ve run into some really cool articles on meta programming in JavaScript - so I was hoping there was a way to emulate this kind of functionality in Javascript. Turns out - there isn’t. Then I ran into a presentation from Jon Resig (Author of jQuery and JavaScript Bad Ass). If you check out his recent presentation on ECMAScript 4 (You can skip ahead to slide #13 & 14) You’ll see that they are specially adding the features I’m talking about to the new ECMAScript 4 (AKA JavaScript 2.0). There are some other neat things in there (there are also some other crazy things that make it feel much like the time I watch PHP4 convert to PHP5 and it felt like they were adding things based purely on emulating other languages).
That’s the good news - the bad news… FireFox 3 (which is currently in beta) will only support JavaScript 1.8. The only reference to a date in the presentation is 2008-2009. I found this blog post that says they are hoping to firm it all up by October of 2008.
Guess that means I’m not going to be waiting for it - since I actually have stuff to get done right now (almost literally - I have a code demo due on Monday for a library I’m working on). At least I know that the renaissance I’ve seen in the JavaScript world is really just getting started.
*Side Note* - To give you an idea of how not a baked cake all of this thinking is - here is a PDF that shows some concerns over some of the features that are possibly going to be included.
Leave a Reply
Moderation Active: Old stuff here... Therefore your comment on this post will be moderated (i.e. don't submit twice !)