www.webdeveloper.com
Results 1 to 7 of 7

Thread: javascript package

  1. #1
    Join Date
    Feb 2004
    Posts
    54

    javascript package

    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.

  2. #2
    Join Date
    Jul 2003
    Location
    Boston Area, Massachusetts
    Posts
    3,489
    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:
    Code:
    <script type="text/javascript" src="foo.js"></script>

  3. #3
    Join Date
    Feb 2004
    Posts
    54
    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.

  4. #4
    Join Date
    Feb 2004
    Posts
    54
    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.

  5. #5
    Join Date
    Feb 2004
    Posts
    54
    A more generaic question would be: whether 2.0 standard is actually currently supported by any browser?

  6. #6
    Join Date
    Jul 2003
    Location
    Boston Area, Massachusetts
    Posts
    3,489
    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.

  7. #7
    Join Date
    Feb 2004
    Posts
    54
    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles