Loading ...
Sorry, an error occurred while loading the content.
 

Loading an external library into a container

Expand Messages
  • olivier.boissin
    Hi, I m trying to load an external library (for example jsval.js ) into a container (which I assume is a standard javascript object, which I ll call jsval )
    Message 1 of 3 , Jul 19, 2006
      Hi,

      I'm trying to load an external library (for example "jsval.js") into a
      container (which I assume is a standard javascript object, which I'll
      call "jsval") .

      So here we go :

      var jsval = { } ;
      Load("jsval.js", jsval);

      But it doesn't work as I expected. Worse, it doesn't work at all.

      jsval.js introduces some functions, such as validateStandard().

      I expected to be able to access thoses functions in the jsval object
      scope, ie : jsval.validateStandard().

      I suppose i did not fully understood how Ajile is suppose to work. Maybe
      i'm just trying to do something Ajile cannot accomplish, I'm quite lost.

      Any hint would be appreciated.

      Thanks,

      Olivier boissin.
    • iskitzdev
      Hi Olivier, Yes I think there is a misunderstanding. Load s container parameter is intended to be a reference to the window object within which the script
      Message 2 of 3 , Jul 21, 2006
        Hi Olivier,
        Yes I think there is a misunderstanding. Load's "container" parameter is intended to be a reference to the window object within which the script  should be loaded. It was named container because at some point I'd like to allow Ajile to be used in non-browser script environments that may not have a "window" object.

        It's interesting to see how you interpreted Load's purpose, it's different. I suppose using Load the way you described would be similar to doing an Import.

        In order to achieve what you wrote about you would need to define a jsval object in your jsval.js file then simply do Load("jsval.js") or Import("jsval").

        To define your jsval object, you can use any of JavaScript's object creation techniques. The examples I've provided on the site and in the download use the "new function()" technique. The following are some examples of how your jsval.js file might look:

        //-- Olivier's jsval Script :: Approach #1
        var jsval = new function()
        {
           // Create jsval.
        validateStandard()
           this.validateStandard = function()
           {
              //function's logic here...
           };
        };

                      or

        //-- Olivier's jsval Script :: Approach #2
        var jsval = new function()
        {
           // Create jsval.validateStandard()
           this.validateStandard = validateStandard;

           function validateStandard()
           {
              //function's logic here...
           }
        };


                      or

        //-- Olivier's jsval Script :: Approach #3
        var jsval =
        {
           // Create jsval.validateStandard()
           validateStandard : function()
           {
              //function's logic here...
           }
        };

        There are even more ways, it's up to you to choose the one that best suits your needs. Approaches #'s 1 & 2 allow you to define private variables and functions, but if you don't need those, Approach #3 can be just as effective and less verbose.

        One thing to understand about using your scripts with Ajile is that Ajile's Load operation does exactly what the browser would do if you wrote a script tag. The contents of the external script file will be executed in the global namespace. This means that if your script doesn't define its logic within an object, its individual variables, functions and statements will exist and be executed in the gobal namespace, the window.

        Ajile's Import and ImportAs functions load the external script file associated with the name you specify. The external script file is expected to define an object matching that name. If the object isn't defined, no shortened-name access can be provided to the script's contained functionality. The script will be loaded and executed but there will be no single object that points to all of the script's functionality. This is how browser environments normally handle scripts.

        If you still have questions or need more clarification let me know.

        -Michael

         

        --- In ajile@yahoogroups.com, "olivier.boissin" <yogi@...> wrote:
        >
        > Hi,
        >
        > I'm trying to load an external library (for example "jsval.js") into a
        > container (which I assume is a standard javascript object, which I'll
        > call "jsval") .
        >
        > So here we go :
        >
        > var jsval = { } ;
        > Load("jsval.js", jsval);
        >
        > But it doesn't work as I expected. Worse, it doesn't work at all.
        >
        > jsval.js introduces some functions, such as validateStandard().
        >
        > I expected to be able to access thoses functions in the jsval object
        > scope, ie : jsval.validateStandard().
        >
        > I suppose i did not fully understood how Ajile is suppose to work. Maybe
        > i'm just trying to do something Ajile cannot accomplish, I'm quite lost.
        >
        > Any hint would be appreciated.
        >
        > Thanks,
        >
        > Olivier boissin.
        >
      • olivier.boissin
        Hi Michael, Thanks for your quick response. Now I realize I didn t understood Ajile s purpose. JSval for instance is a form validation framework
        Message 3 of 3 , Jul 21, 2006
          Hi Michael,

          Thanks for your quick response. Now I realize I didn't understood
          Ajile's purpose.

          JSval for instance is a form validation framework
          (http://developer.berlios.de/projects/jsval/) which comes with lots of
          functions declared in the global namespace, which is problematic
          because it makes conflicts with other libraries I'd like to use
          (identical functions names).

          I thought Ajile would allow me to encapsulate thoses functions into a
          namespace *without* having to rewrite the library. I must admit it's
          quite ambitious and probably impossible to do only with Javascript,
          but I'm still keeping hope.

          Anyway, thanks again for your help.

          Cheers,

          Olivier BOISSIN.


          --- In ajile@yahoogroups.com, "iskitzdev" <iskitzdev@...> wrote:
          >
          > Hi Olivier,
          > Yes I think there is a misunderstanding. Load's "container" parameter is
          > intended to be a reference to the window object within which the script
          > should be loaded. It was named container because at some point I'd like
          > to allow Ajile to be used in non-browser script environments that may
          > not have a "window" object.
          >
          > It's interesting to see how you interpreted Load's purpose, it's
          > different. I suppose using Load the way you described would be similar
          > to doing an Import.
          >
          > In order to achieve what you wrote about you would need to define a
          > jsval object in your jsval.js file then simply do Load("jsval.js") or
          > Import("jsval").
          >
          > To define your jsval object, you can use any of JavaScript's object
          > creation techniques. The examples I've provided on the site and in the
          > download use the "new function()" technique. The following are some
          > examples of how your jsval.js file might look:
          >
          > //-- Olivier's jsval Script :: Approach #1
          > var jsval = new function()
          > {
          > // Create jsval.validateStandard()
          > this.validateStandard = function()
          > {
          > //function's logic here...
          > };
          > };
          >
          > or
          >
          > //-- Olivier's jsval Script :: Approach #2
          > var jsval = new function()
          > {
          > // Create jsval.validateStandard()
          > this.validateStandard = validateStandard;
          >
          > function validateStandard()
          > {
          > //function's logic here...
          > }
          > };
          >
          > or
          >
          > //-- Olivier's jsval Script :: Approach #3
          > var jsval =
          > {
          > // Create jsval.validateStandard()
          > validateStandard : function()
          > {
          > //function's logic here...
          > }
          > };
          >
          > There are even more ways, it's up to you to choose the one that best
          > suits your needs. Approaches #'s 1 & 2 allow you to define private
          > variables and functions, but if you don't need those, Approach #3 can be
          > just as effective and less verbose.
          >
          > One thing to understand about using your scripts with Ajile is that
          > Ajile's Load operation does exactly what the browser would do if you
          > wrote a script tag. The contents of the external script file will be
          > executed in the global namespace. This means that if your script doesn't
          > define its logic within an object, its individual variables, functions
          > and statements will exist and be executed in the gobal namespace, the
          > window.
          >
          > Ajile's Import and ImportAs functions load the external script file
          > associated with the name you specify. The external script file is
          > expected to define an object matching that name. If the object isn't
          > defined, no shortened-name access can be provided to the script's
          > contained functionality. The script will be loaded and executed but
          > there will be no single object that points to all of the script's
          > functionality. This is how browser environments normally handle scripts.
          >
          > If you still have questions or need more clarification let me know.
          >
          > -Michael
          >
          >
          > --- In ajile@yahoogroups.com, "olivier.boissin" <yogi@> wrote:
          > >
          > > Hi,
          > >
          > > I'm trying to load an external library (for example "jsval.js") into a
          > > container (which I assume is a standard javascript object, which I'll
          > > call "jsval") .
          > >
          > > So here we go :
          > >
          > > var jsval = { } ;
          > > Load("jsval.js", jsval);
          > >
          > > But it doesn't work as I expected. Worse, it doesn't work at all.
          > >
          > > jsval.js introduces some functions, such as validateStandard().
          > >
          > > I expected to be able to access thoses functions in the jsval object
          > > scope, ie : jsval.validateStandard().
          > >
          > > I suppose i did not fully understood how Ajile is suppose to work.
          > Maybe
          > > i'm just trying to do something Ajile cannot accomplish, I'm quite
          > lost.
          > >
          > > Any hint would be appreciated.
          > >
          > > Thanks,
          > >
          > > Olivier boissin.
          > >
          >
        Your message has been successfully submitted and would be delivered to recipients shortly.