Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variables declared in outer function can not be cached (v1.2) #1

Closed
jingwood opened this issue May 23, 2013 · 1 comment
Closed

Variables declared in outer function can not be cached (v1.2) #1

jingwood opened this issue May 23, 2013 · 1 comment
Assignees

Comments

@jingwood
Copy link
Member

Variables declared in outer function but used in inner function can not be cached so the following code does not work in ReoScript.

fun1 = function() { 
  var cached_var = 10;

  return function() {
    console.log('cached_var = ' + cached_var);
  };
} ();

fun1();

The result is that cached_var is null.

@ghost ghost assigned jingwood May 23, 2013
@jingwood
Copy link
Member Author

Functions will cache the call-scope where function was defined in. This issue has been fixed and planned to be available since v1.3.

Now overriding a function by 'apply' method will be available. (The original code of following sample was published in StackOverflow http://stackoverflow.com/questions/9134686/adding-code-to-a-javascript-function-programatically)

var t = debug.assert;

t( Function.prototype.hasOwnProperty('apply') );

var a = 0;

function fun1() {
     a += 10;
}

fun1();
t(a, 10);

fun1 = (function() {
var cached_function = fun1;
     return function() {

     // code before override goings here
     a += 5;

     cached_function.apply(this, __args__);      // use .apply() to call origial function

     // code after override goings here
     };
}());

fun1();                 // now fun1 is an override function
t(a, 25);               // a is 25

The test case at:
https://github.com/unvell/ReoScript/blob/master/TestCase/tests/021_fun.xml

jingwood added a commit that referenced this issue Jun 17, 2013
- New: Performance improving
- New: New error handling method (#3)
- New: Handle or throw syntax errors at pre-interpret-time
- New: Handle const values at pre-interpret-time
- New: Inner function can cache its outer call-scope (#1)
- New: Inner function can be pre-interpreted (call before define is
available) (#2)
- New: Max call-stack detection added
- New: Minus operator can be used to calculate elapsed milliseconds with
two date objects
- New: IDirectory interface is available to property access and
enumeration (#4)
- New: Information about functions and variables is available after
compiling
- Fixed: Function scope and call-scope has been fixed
- Fixed: Exception caused when array resizing has been fixed
- Changed: .NET IList interface can be accessed directly (DirectAccess
mode is unnecessary)
- Changed: Reform library namespaces
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant