0

I am designing a platform for a site, where site users are allowed to execute scripts on JSON in browser window only

Here is a screen shot of page:

enter image description here

user will be getting the JSON, and whatever script is written in form will execute on JSON.

I am using AngularJS as my front end scripting tool. I know there are ways to execute script using JavaScript eval() funciton. Also another way to execute script is

function runMe() {
        console.log('here you  go');
}
var fnstring = "runMe";
var ex = window[fnstring];
ex.apply();   

But I am looking for a better approach in JavaScript/AngularJS only. Is there any way through which I can extend my Angular Scope function dynamically. Or is there any other Object oriented approach, I should use in order to maintain the script execution safe and optimize.

2
  • What do you mean execute on Json? Commented Jan 30, 2015 at 14:27
  • @Wawy : execute on Json means, basic javascript operation (push,indexOf,etc ) that will be written in script will apply on(execute upon) Json and will modify the json data accordingly Commented Jan 30, 2015 at 14:42

1 Answer 1

0

Based on your comment you could do something like this:

Assuming you store your JSON in a variable called myArr.

You could execute expressions against that Array:

var myArr = [{a: 1}];
var expression = "this[0].b = this[0].a + 2"; //example expression
$parse(expression)(myArr);
console.log(myArr[0]);

More on angular expressions: AngularJS docs on expressions

And $parse: AngularJS docs on $parse

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.