JavaScript, inheritance via prototype?

Last week I was on holiday (hence zero posts) and I found myself with a little free time for a private project. I thought that given all the noise around AJAX, JSON, WPF/E and the Vista side bar I'd better get back into JavaScript (I'll post more about the project itself soon). Most web developers have done something with JavaScript at some point or another and I'm no different. I have written many a DHTML script generating custom graphs in pure HTML using tables and XML. However, after spending a little time reading a book I bought about ~7 years ago on JavaScript whilst on holiday I now realise that I never really knew JavaScript in the first place, let alone get back into it!

I am simply amazed at how much you can do with the language without ever really knowing it. I have seen JavaScript as a credential on many a CV (including my own) and I never really thought to question it, but after my own recent experience I'm sure that many a programmer thinks they already know about JavaScript but whether they really know it is another question.

I wonder if you we're to ask them how to create a JavaScript class called Customer that had an instance method call getServices(), a property called customerId as well as static property called NullCustomerId and a static method called RenderCustomer(), oh, and by the way the class must also inherit from a base class called Contact; how many of those candidates could actually write me a JavaScript class that looked that way? I know I certainly could not have until very recently.

What I'm really impressed with is that I never needed to know those things to get what I needed to do done. I have written 100's if not 1000's of lines in JavaScript over the years and now realise I never really understood it, all I ever wrote were global functions - now that's a great (not a good, but a great) language that can hide that much of it's power and still be useful.

I'm now comfortable that I know how to do the above, should that be required, along with other features such as anonymous methods, associative arrays, inheritance via prototypes and using functions as data - all JavaScript goodness. But I'm also happy that other people don't and still consider themselves proficient in JavaScript, that's a feature and the power of the JavaScript language.

No comments: