Follow Slashdot stories on Twitter

 



Forgot your password?
typodupeerror
×
Mozilla

Journal Gopal.V's Journal: Standalone Javascript: Breaking out of the browser

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());

This discussion has been archived. No new comments can be posted.

Standalone Javascript: Breaking out of the browser

Comments Filter:

Don't get suckered in by the comments -- they can be terribly misleading. Debug only code. -- Dave Storer

Working...