How can I fix the error message "Scope.eval is not a function" ---

    Feb 28 2012 | 12:38 am
    I had a file called include.js that I found on the net that allows me to easily include other files in my js code. Works beautifully on Max 5 but fails on Max 6 with the error above.
    There's a comment that eval has been disabled on Max 6 so I'm wondering if there's another way to get the same functionality.

    • Feb 28 2012 | 3:29 am
      To answer my own question, I think the following works as an alternative for global stuff, which is all I need
      Instead of the original line
      I used the following instead
      var myFunction = new Function(mem);
      The only difference with this version is that it doesn't have the 'scope' context but I'm not sure how necessary that is.
      Anyone know?
    • Feb 28 2012 | 9:32 am
      Couls you post you include.js? What exactly is it supposed to do
    • Feb 28 2012 | 12:29 pm
      See this link. It's very handy.
    • Feb 29 2012 | 1:03 pm
      Hi D,
      as far as my knowledge goes the main difference between eval() and using an anonymous Function() constructor is the scope they have access too.
      eval can access scopes outside itself, the Function constructor can't. (This is the reason why some say "eval is evil." and I guess the reason why it was removed... )
      This means practically:
      var myFunction = function() {
         var a = 1;
         return a;
      will return 2. While
      var myFunction = function() {
         var a = 1;
         (new Function("a=a+1"));
         return a;
      will return 1 (as the a inside the constructor is not in the same scope as the one outside.
      As fas as I see it that means for the solution you mentioned that you can run the code inside the included file on startup/loading of your [js ] - object but you cannot execute any function that are inside. (At least i am not able to do so on a windows machine...).
      A workaround to this problem I could think of is this one:
      Alter the end of include.js to
      var myFunction = new Function(mem);
      return myFunction();
      and use the include function inside your [js ] - object like this.
      var myIncludedObject = include(this,"/Path/To/File.js");
      function bang() {
      I got this to work if your included JS-file has this sightly odd/not slick design pattern:
      /Path/To/File.js :
      return {
      	myProperty: 2222,
      	myMethod: function(MyVar) {
      But maybe someone has a more elegant solution .....