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

Function return another function and executing it not working. #762

Closed
ionescuvictor opened this Issue Dec 10, 2016 · 5 comments

Comments

Projects
None yet
2 participants
@ionescuvictor

ionescuvictor commented Dec 10, 2016

It works with normal eval but not with the mathjs parser, here is an example.Thank you.

 var scope = {
        obj: {
            window: window,
            prop: 42,
            setAge: function () {
                var myJsName = "testff";
                return function () {
                    return myJsName;
                }
            }
        }, 
    };

    console.log(scope.obj.setAge()());

    // retrieve properties using dot notation or bracket notation



    function evalInContext(js, context) {
        //# Return the results of the in-line anonymous function we .call with the passed context
        return function () { return eval(js); }.call(context);
    }

    console.log(evalInContext('scope.obj.setAge()()', scope))
   console.log(math.eval('obj.setAge()()', scope));

@josdejong josdejong added the bug label Dec 10, 2016

@josdejong

This comment has been minimized.

Owner

josdejong commented Dec 10, 2016

Thanks for reporting, that should indeed work.

@josdejong

This comment has been minimized.

Owner

josdejong commented Dec 10, 2016

I've fixed this in the develop branch, the fix will be available in the first next release.

@josdejong josdejong closed this in a5df5e4 Dec 15, 2016

@josdejong

This comment has been minimized.

Owner

josdejong commented Dec 15, 2016

This has been fixed now in v3.8.1

@ionescuvictor

This comment has been minimized.

ionescuvictor commented Dec 20, 2016

Great! ty for fixing this.A thing to further watch out are static members of a function.

josdejong added a commit that referenced this issue Dec 20, 2016

@josdejong

This comment has been minimized.

Owner

josdejong commented Dec 20, 2016

A thing to further watch out are static members of a function.

This works as it should right now, I've added another unit test to prevent any regressions here (see 572ec25)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment