class libraries

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • WStoreyII

    class libraries

    it there as way to build class library's of functions and stuff that can be
    used in javascript likein vb.net or c#

    WStoreyII


  • Vincent van Beveren

    #2
    Re: class libraries

    JavaScript does not really have classes, but yes, you can include
    external javascript files:

    <script language="JavaS cript" src="myexternal .js"></script>

    Note that this can only be done in HTML.



    WStoreyII wrote:[color=blue]
    > it there as way to build class library's of functions and stuff that can be
    > used in javascript likein vb.net or c#
    >
    > WStoreyII
    >
    >[/color]

    Comment

    • Grant Wagner

      #3
      Re: class libraries

      WStoreyII wrote:
      [color=blue]
      > it there as way to build class library's of functions and stuff that can be
      > used in javascript likein vb.net or c#
      >
      > WStoreyII[/color]

      Sure. Create your objects with their associated methods and properties, put
      them in a .js file and include them on your page with:

      <head>
      <!-- other stuff -->
      <script type="text/javascript" src="MyDictiona ry.js"></script>
      </head>

      Then in MyDictionary.js you might have:

      function MyDictionary() {
      this.RemoveAll( );
      }
      MyDictionary.pr ototype.RemoveA ll = function() {
      this.obj = {};
      this.Count = 0;
      }
      MyDictionary.pr ototype.Add = function(key, value) {
      if (this.obj[key] != null) {
      return null;
      }
      this.obj[key] = value;
      this.Count++;
      return value;
      }
      MyDictionary.pr ototype.Exists = function(key) {
      return (this.obj[key] != null);
      }
      // etc

      And you could use it in your page like this:

      <script type="text/javascript">
      var y = new MyDictionary();
      y.Add ("a", "test");
      if (y.Exists("a")) {
      document.write( "a exists in MyDictionary");
      }
      </script>

      --
      | Grant Wagner <gwagner@agrico reunited.com>

      * Client-side Javascript and Netscape 4 DOM Reference available at:
      *


      * Internet Explorer DOM Reference available at:
      *
      Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.


      * Netscape 6/7 DOM Reference available at:
      * http://www.mozilla.org/docs/dom/domref/
      * Tips for upgrading JavaScript for Netscape 7 / Mozilla
      * http://www.mozilla.org/docs/web-deve...upgrade_2.html


      Comment

      Working...