Re: Javascript: Time Traveller From the Year 1962!

[prev] [thread] [next] [lurker] [Date index for 2005/04/08]

From: David Wheeler
Subject: Re: Javascript: Time Traveller From the Year 1962!
Date: 23:45 on 08 Apr 2005
On Apr 8, 2005, at 3:15 PM, Michael G Schwern wrote:

> I have to write my own include function.  This include function isn't 
> even
> native to Javascript, it relies on the browser DOM.  I have to cut & 
> paste
> this code into every JS file which wants to include another.  I have to
> cut & paste code so that I do not have to cut & paste code.

My understanding from talking to some JS folks on IRC is that 
JavaScript was never designed to do I/O. Too much of a security threat 
in browsers. Of course, this makes it practically useless as a 
general-use language (maybe one can hack around that in Rhino, but I 
haven't played with it, yet).

   http://www.mozilla.org/rhino/

So, without I/O, all you can do is ask the JavaScript host (Mozilla, 
IE, Safari, whatever) to do it for you. They don't provide a general 
way, either, so you have to use the DOM to create a new script element. 
Other than the document.write hack, there's this hack:

    document.createElement("script");

Uh, then you can set the src and type attributes. But don't expect to 
use any of that code before the body.onload event fires.

The upshot is that I don't think that there can ever be a CJSAN. Pity.

> In related news... Lua.  NO NAMESPACES!  WHAT THE HELL PEOPLE?!  The
> tables-as-namespaces makes Perl 5's OO system look clean and well 
> thought
> out.

At least you can hack around this one by adding properties to 
functions, including constructors. I did this to create a singleton 
object in TestBuilder.js;

function TestBuilder () {
     if (!TestBuilder.Test) TestBuilder.Test = this;
     return TestBuilder.Test;
}
TestBuilder.Test = TestBuilder.prototype;

Cheers,

David

Generated at 12:00 on 12 Apr 2005 by mariachi 0.52