FAQ Database Discussion Community


How to return a random show function effect with javascript

javascript,jquery,arrays,random,eval
I'm trying to show some element with a random effect. I store those functions in an array and try to get a random function from that array, but the functions seem to rum at the same time. $.random_show = function(){ (function($) { $.rand = function(arg) { if ($.isArray(arg)) { return...

What is an alternative to using 'eval' to accessing a variable by name to “sync” it with another?

javascript,eval
I want to keep two JavaScript variables in sync when I run a function. The variable that is to be pointed to is in an object. The code I have so far is this: var myname = "bob"; var thevar = ""; var varobj = {tvar: "myname"}; var syncvar =...

How to avoid using JavaScript eval() in user-defined function

javascript,json,eval
I'm trying to make a generic table-top RPG helper web app. It has to be generic because Wizards of the Coast is very protective of their copyrights. So, in order to avoid cease-and-desists, the system has to be capable of loading arbitrary rules. That said, my buddies and I (along...

What's wrong with `var myEval = eval; myEval(“2+2”)`

javascript,eval
As per MDN-EVAL You cannot indirectly use the eval function by invoking it via a name other than eval(); if you do, a runtime error might occur. For example, you should not use the following code: var x = 2; //1 var y = 4; //2 var myEval = eval;...

Using eval to print an array value

php,arrays,eval
$cars = array ( array("Volvo",22,18), array("BMW",15,13), array("Saab",5,2), array("Land Rover",17,15) ); $key = '[1][0]'; $str = '$cars'.$key; echo $str."\n"; eval($str); Output: $cars[1][0] PHP Parse error: syntax error, unexpected end of file in ... : eval()'d code on line 1 I'm expecting it to print the value, i.e BMW...

R convert character to dataframe column name and then replace values in a column

r,eval,assign
I was able to get content of the column pointed by character variable b. But i want to make column emp 0. How could i do that? emp=c(1,2,30) abc=data.frame(emp) b="emp" #below line gives content of column emp eval(parse(text=paste("abc$", b, sep = ""))) #how can i replace each value in column...

Is this eval() in python safe?

python,eval,code-injection
consider this code: from re import sub input = request.POST['input'] sub_pattern = {'1':"sub('pattern1','txt1',input)", '2':"sub('pattern2','txt2',input)", } eval(sub_pattern['1']) is there code-injection in this code? can you provide POC on this code injection?...

appending multiple similar functions to protoype

javascript,node.js,eval
I want to avoid redundant code for one of my projects, which is a simple logger. This logger needs functions like *.alert, *.notice, etc. and I also decided to assign aliases to them (.alert = .al, etc.). This leads to multiple similar functions, that only differ by one number, and...

Can an inserted