0 Replies Latest reply on Aug 31, 2009 10:10 AM by andrewalb

    Unable To Instantiante an Object From A Different Script Object.


      I am writing some code for a new form and I wanted to put each 'object' into its own script object - to keep things clean.

      However, I am having difficulty instantiating one object from another object. When you try to instantiate an object from a different script object

      execution of the code stops without any errors outputted to the console.


      The only workaround I have been able to come up with is to create another function in the same script object that my object is in and then from that wrapper function return the new object.


      I also tried passing the script object into my function - but that did not work either.


      Does anyone have any idea as to why this is...?


      Below is some code samples that I was using to try and figure out just what was happening.


      The code below is broken into two different script objects - one that has the functions and the other that calls them.

      The whole process is started with a button click event.


      myTest Script Object:


      //An instantiable object


      function person(name,age){

          this.name = name;
          this.age = age;       


      //A wrapper function that returns the object.

      function getNewPerson(name,age){

           return new person(name,age);



      myCaller Script Object


      function TestItOut(){




           var gp = myTest.getNewPerson("Jeffrey",27);


           var p = new myTest.person("Andrew",29);





      Button Object That Calls Routine in MyCaller Script Object


      On Click:





      Below is the output:



      Line 1: Starting...
      Line 2:({name:"Jeffrey", age:27})



      PLEASE NOTICE that the call to instantiate a person by itself without the wrapper class does not return anything.

      In fact - it will halt execution of the script without any errors outputted to the console....

      This is why the first object is outputted to the console (because it uses the wrapper function).

      However, the one where I tried to instantiate it by itself outputted nothing and halted excution of the script.


      Any insights would be appreciated.