Skip to content

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

@ionescuvictor

Description

@ionescuvictor

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));

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions