Click to See Complete Forum and Search --> : javascript package
peiguo
03-08-2004, 10:14 PM
I don't know whether javascript package is actually supported by any browser today.
I made up two files:
file test10.js:
package test10;
function a() {
alert("in package");
}
file test2.html:
<html>
<script language="JavaScript">
import test10.a from "file:///c:/src/javascript/test10.js";
</script>
<body onLoad="a()">
</body>
</html>
It didn't work with this IE I have, and give an error message complaining line 3 of test2.html, that import statement.
The question is that, whether it is really an error, or just because the browser does not support package.
fredmv
03-08-2004, 10:20 PM
It seems almost as if you're confusing Java with JavaScript. Generally, to include an external JavaScript libary, you'd do something along these lines:<script type="text/javascript" src="foo.js"></script>
peiguo
03-08-2004, 10:24 PM
No, not true.
javaScript 2.0 standard does support this new concept. It just a matter whether it has already been supported by any browser.
This is a great news, as now you can manage your script in a more organized way.
peiguo
03-08-2004, 10:30 PM
At first glance, there is an obvious difference:
script tag allows you to link to an .js file, but it will bring in the entire file, where import allows you to import a subset of functions from a package.
peiguo
03-08-2004, 10:31 PM
A more generaic question would be: whether 2.0 standard is actually currently supported by any browser?
fredmv
03-08-2004, 10:40 PM
That's understandable. JavaScript 2.0 (as far as I'm concerned) isn't really implemented at all yet. Though, it perhaps will be sometime in the future. As for now, I don't see much of a problem using the standard notation for including external JavaScript.
peiguo
03-08-2004, 11:06 PM
This becomes a problem when you have many .js files, and you don't want to copy and paste.
On one hand, you can have multiple script tags (so you can link to multiple .js files), on the other hand, when there is a naming comflict, there is no way to resolve it.
Now copy and paste comes to rescue, and you end up with multiple copies of one piece of logic being spreaded everywhere.