An include() for Javascript

schwern on 2005-04-10T08:55:53

TorgoX is a genius. A maaaaaad genius who will soon DESTROY US ALL!!!! Meanwhile, he produces stuff like this.

What is it? Its an include() routine for JavaScript! It reduces the duplicated code in the HTML down to...



the_real_code.js now has bootstrap() (or in my version, include()) available and can include other Javascript files right in its own code... JUST LIKE A REAL LANGUAGE! Golly!


DynAPI got there before you

barbie on 2005-04-10T15:57:44

Since 1998 I've been using Javascript for exactly this, curtesy of DynAPI (originally a Dan Steinman project). You can do simple things such as:
<script language="Javascript" src="../src/dynapi.js"></script>
<script language="Javascript">
DynAPI.setLibraryPath('../src/lib/');
DynAPI.include('d ynapi.api.*');
</script>
To load all your dynapi.api.* library files. Or you can simply include a single file.

PS: There is no space between 'd' and 'ynapi' in the above example. use.perl code has inserted it for some strange reason.

Re:DynAPI got there before you

Smylers on 2005-04-11T10:05:13

PS: There is no space between 'd' and 'ynapi' in the above example. use.perl code has inserted it for some strange reason.

One way in which people can abuse sites is by posting comments that contain ridiculously long strings of characters with no spaces in it them: web-browsers don't have anywhere to split the line, so the box they are in gets massively extended sideways, pushing out other columns, and generally messing up the page.

Slash avoids this by inserting spaces into long 'words', with the unfortunate effect you've experienced. Sometimes you can make it less bad by inserting a space yourself somewhere else. For example, if you put a space between the open paren and the first quote mark, that would still be valid JavaScript (if a little ugly).

Smylers

Re:DynAPI got there before you

barbie on 2005-04-11T11:07:14

Except that in the <ecode> block there were both spaces and newlines! Plus it didn't do it for the line above it :(