With great power comes greater responsibility!

Recently I was reading an article about Javascript, and the reasons it has become the language of choice for dynamic, client side web application requirements.
But the most interesting plus was the ‘runtime compiler’ which our little juju boasts of.
Majority of object-oriented (OO) languages define a fundamental Object type of some kind from which all other objects are derived. Likewise in Java Script, the fundamental Object serves as the basis for all other objects, but that’s where the comparison stops.

Consider you want to declare an object Motorcycle and want to attach attributes to them, in your traditional OO programming language you’d need to declare a class with some predefined variables.

Java makes all this a tad bit easy by allowing you to declare attributes on the go.
var bike = new Object();
bike.make = ‘Bajaj’;
bike.model = ‘Pulsar’;
bike.year = 2010;
bike.purchased = new Date(2010,4,26);

We create a new object bike, and assign the attributes on the go, without declaring them beforehand. This is one of the most powerful tools of Java.

But everything comes at a price, consider a later stage of time when you want to update your attribute named purchased.

You type in:
bike.purchased = new Date(2010,4,27);
and you make a small typo resulting in
bike.purhcased = new Date(2010,4,27);
notice the change in spelling, but Java very neatly declares another variable by that name, and you have no Compiler to warn you against ‘No such variable declared’!
You might sit wondering why the new date does not reflect  for hours unless you realize the ‘ch’->’hc’ in purCHased!

As I said earlier… With great power comes great responsibility!

Leave a Reply