< April 2005 >
SuMoTuWeThFrSa
      1 2
3 4 5 6 7 8 9
10111213141516
17181920212223
24252627282930
Fri, 29 Apr 2005:
The first thing a young Java programmer learns while reading through his first java book is the get/set convention. But when you look at C# you will notice that it has a properties construct (purely syntactic sugar) which enforces a few more good design rules and in general makes code cleaner. Properties in Javascript is pretty much undocumented and I've not found much documentation on this - and it is a Mozilla only hack.
function MyClass() { }

MyClass.prototype.__defineGetter__("foo", function() {
return "I am the foo";
});

MyClass.prototype.__defineSetter__("foo", function(value) {
    print(value + " is no good");
});

var a = new MyClass();
print(a.foo);
a.foo = "slashdot";
Would happily give the following output
I am the foo
slashdot is no good
The code is pretty much self-explanatory. If you don't think this is of much use, continue reading.
if(!document.all)
{

Event.prototype.__defineGetter__("offsetX", function () {
   return this.layerX;
});

Event.prototype.__defineGetter__("offsetY", function () {
   return this.layerY;
});

}
Javascript is a truly powerful language. But all graduate students try is to dig into assembly and kernel programming - leaving javascript and webdev to the lesser mortals. It's time all that changed.

posted at: 00:27 | path: /slashdot | permalink | Tags: