4 Replies Latest reply on May 30, 2011 7:23 PM by moluapple

    When function.toSource() meet jsxbin...

    moluapple Level 4

      function sayHello(appName) {
           alert('Hello ' + appName);
      }
      app.doScript(sayHello.toSource() + '("Indesign!")');
      

       

      When export above codes to jsxbin with ESTK, and then run the jsxbin file in Indesign, it will failed.

       

      By add one line:

      $.writeln (sayHello.toSource() + '("Indesign!")');

       

       

      and what return in console is:

      (function sayHello() {  [compiled code] } )("Indesign!")

       

      So, any idea?

        • 1. Re: When function.toSource() meet jsxbin...
          Harbs. Level 6

          Don't use toSource()...

           

          You can run a doScript by referencing the function name.

           

          Harbs

          1 person found this helpful
          • 2. Re: When function.toSource() meet jsxbin...
            moluapple Level 4

            Thank you for reply.

            Yes, if no argument is needed, app.doScript( fn() ) is just ok, but app.doScript( fn(args) ) will also be execute but then throw an error. May i missing something?

             

            I just want to know how toSource(), toString() and uneval() are handled by jsxbin, because all these will not work.

            • 3. Re: When function.toSource() meet jsxbin...
              John Hawkinson Level 5

              It might be useful if you told us what you really wanted to accomplish.

              Yes, if no argument is needed, app.doScript( fn() ) is just ok, but app.doScript( fn(args) ) will also be execute but then throw an error. May i missing something?

              You must be confused. app.doScript(fn()) evaluates the function fn() and passes the result to app.doScript(). You probably mean app.doScript(fn). If you want to pass arguments, you can use the 3rd argument of doScript:

               

              app.doScript(fn, undefined, [1,2,3]);

               

              You might have to consult the global arguments array to get them out though....

              I just want to know how toSource(), toString() and uneval() are handled by jsxbin, because all these will not work.

              They don't work! That's the whole point! Otherwise you could get the source out of the jsxbin. What's uneval()? Do you mean eval()?

              • 4. Re: When function.toSource() meet jsxbin...
                moluapple Level 4
                If you want to pass arguments, you can use the 3rd argument of doScript:

                Aha, I forget the withArguments argument of doScript. So that's ok now.

                uneval() is something like toString(), E.g.: uneval(sayHello) will return

                (function sayHello(appName) {   alert('Hello ' + appName); })

                They don't work! That's the whole point! Otherwise you could get the source out of the jsxbin.

                That make sense! Just want to comfirm this.

                But when come to bridgeTalk.body, toSource() and uneval() things are useful, and since I rarely export jsxbin, I can still use them as well.