Error with code in jsextensions

    Jul 26 2013 | 11:49 pm
    I moved some js code into a library and put it in jsextensions so that I can reuse it. But when I access one of the functions in this library I get following error...
    js: processinglib.js: Javascript ReferenceError: outlet is not defined, line 115
    Why would outlet not be defined? Is it not a global method?

    • Jul 28 2013 | 9:06 pm
      Are you calling it when the object is instantiated? The outlets might not have had time to be created - try deferring the function call, moving it from your global code, or setting it up in a loadbang() function. It's hard to tell if the cause is anything else without seeing your code.
    • Jul 29 2013 | 2:25 pm
      Yes, I am calling the function after the patcher and objects are instantiated. I am triggering it manually. Are you saying that when Max starts up, it loads the files in jsextensions and outlet is undefined? According to Max documentation, outlet is a method within the jsthis object. Does the jsthis object not exist at startup? Why would it not find it by the time I call the function?
    • Jul 29 2013 | 10:47 pm
      I meant that you couldn't have something like
      by itself in your code if it's not part of a function. Try loading just that line in a [js] object and re-open the file - you'll get an error message because the outlet doesn't exist in the global code. Do you have a snippet of your code that replicates the issue so I can take a closer look?
    • Jul 29 2013 | 11:03 pm
      This is the function that is causing the error. It is loaded in a file that is in jsextensions.
      function drawProcessingScene() { var theImage = null;
      mgfx.identity_matrix(); theImage = new Image(mgfx.pop_group()); mgfx.image_surface_draw(theImage);
      theImage.tonamedmatrix(; outlet(0, "jit_matrix",;
    • Jul 30 2013 | 10:04 pm
      Okay I simplified it even more. If you put this function in a file in jsextensions, it will error out.
      function outletRelay(msg) { outlet(0, msg); }
      Could this be some problem with the jsthis object? Perhaps it does not exist when source in the jsextensions directory is loaded?
    • Jul 30 2013 | 10:38 pm
      How and when are you calling it from your main patch? Could you ZIP up all the files and attach them here so I can take a run exactly what you're running?
    • Jul 30 2013 | 11:25 pm
      Okay, here you go.
    • Jul 31 2013 | 12:33 am
      Hmmmm, I tried passing the scope across with no luck (perhaps someone knows more about this than me), otherwise my suggestion would be including your patcher-interfacing code in the main js and any utility functions in the jesextensions, for example:
      function bang() {
          outlet(0,outletRelay("test message"));
      function outletRelay(msg) {
          return msg + "123";
    • Aug 05 2013 | 2:41 pm
      I really feel this is an issue that needs clarification from someone at Cycling. What is the expectation of what I can access from code that is loaded in jsextentions? Is the jsthis object instantiated at that time? Why can I not access the function "outlet"?
    • Aug 05 2013 | 7:43 pm
      Your functions in jsextensions are compiled as global code outside the concept of the js "this" object. When you call outlet() an an ordinary js instance it is calling this.outlet(), but in the jsextensions code there is no similar this. You will need to change your functions to something like the following where you pass in your js "this" object to the function in order to be able to call the outlet functions of that object.
      function doit(myObject) { myObject.outlet(0,"bang"); }
      Hope this helps.
    • Aug 05 2013 | 11:10 pm
      Thanks Joshua for your insight. It is working much better now.