javascript classes in separate files?


    Apr 21 2006 | 5:42 pm
    hello,
    apologies in advance if this is a dumb question, javascript is not my
    first language and i'm still getting used to it's funky prototype-
    based object-oriented-ness.
    I'm trying to break up a huge file of code into smaller files, each
    with a single javascript class in them. Each file compiles fine on
    it's own (after loading them into the [js] object), but I can't seem
    to get inheritance to work - when I create a test patch that
    instantiates a class defined in an external file, I get "ClassName is
    not defined" in the max window. I tried putting each file in the
    same directory as the patch I'm testing them with, and also in the
    C74/jsextensions directory.
    I tried creating a test file containing only "var j3d = new
    Jitter3dUtilsInterface();" and it didn't give any errors. But, when
    I created a js file called test.js with the line "post("testing")"
    and put that in the jsextensions directory, I didn't see any out put
    to the max window. I feel like I'm missing something simple here,
    but I've been through the javascriptinmax manual and came up empty.
    Please, someone save my sanity... i've written 2,000 lines of code in
    4 days and my eyes are all blurry...
    thanks,
    evan

    • Apr 21 2006 | 6:01 pm
      In case anyone's interested, I put the code here:
      It's for making jsui GUI buttons, one is a simple Button class that
      responds to UI events, the other is an extension of that, that
      displays an icon (loaded from an image file with jsui's Image
      object). It's still rough, but possibly useful. Any feedback
      appreciated...
    • Apr 21 2006 | 7:18 pm
      Which version of Max are you using ? post is global since 4.5.5, I
      think. This could explain why... or not...
      Best,
      ej
    • Apr 22 2006 | 12:26 am
      max 4.5.7, jitter 1.5.2
      not sure what you mean, if post() was global, wouldn't i see output
      in the max window?
      my whole goal is to be able to have a class defined in a file, say it
      was named "test.js", located in the jsextensions folder, and
      contained something like:
      function Test()
      {
      this.test = function() { post("testing"); }
      }
      then I could create another js file, called "testing_test.js":
      var tester = new Test();
      tester.test();
      And I should see "testing" printed to the max window.
      Right?
      I hope this makes sense, please let me know if I'm not being clear.
      thanks,
      -Evan
    • Apr 22 2006 | 2:36 pm
      On 22 avr. 06, at 02:26, evan.raskob wrote:
      > max 4.5.7, jitter 1.5.2
      >
      > not sure what you mean, if post() was global, wouldn't i see output
      > in the max window?
      Before 4.5.5 it wasn't possible to call the post() method inside the
      jsextensions folder.
      > And I should see "testing" printed to the max window.
      > Right?
      It doesn't help much more, but it works here : max 4.5.7 on mac
      10.4.6 and windows.
      ej