< April 2005 >
SuMoTuWeThFrSa
      1 2
3 4 5 6 7 8 9
10111213141516
17181920212223
24252627282930
Tue, 26 Apr 2005:
The major problem most people have with Javascript is that there is no easy way to test your code outside the browser. Often it so happens that you might want to test out a string split or array splice quickly. Here's a quick tip on getting a python'ish javascript shell.
/usr/lib/firefox-1.0/run-mozilla.sh /usr/lib/firefox-1.0/xpcshell
This should give you something like
js> a = [42, "is" , "the" , "answer"]
42,is,the,answer
js> a.sort()
42,answer,is,the
You can run your javascript code like this and pretty much everything outside the DOM and Window stuff can be well tested. And lastly the ultimate javascript hack of all time - Object orientation.
function base() { }

base.prototype.myname = function () { return "I am base"; }

function derieved()
{
	this.base = base;
	this.base();
}

derieved.prototype = new base;

derieved.prototype.__myname = derieved.prototype.myname;

derieved.prototype.myname = function () { return "I am derieved"; }

print(new derieved().myname());
print(new derieved().__myname());

posted at: 22:03 | path: /slashdot | permalink | Tags: