You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Variables declared in outer function can not be cached (v1.2) #1
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
Activity
jingwood commentedon Jun 11, 2013
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)
The test case at:
https://github.com/unvell/ReoScript/blob/master/TestCase/tests/021_fun.xml
Release v1.3