eval

How to write this JavaScript code without eval?

旧城冷巷雨未停 提交于 2019-12-23 17:24:39
问题 How to write this JavaScript code without eval? var typeOfString = eval("typeof " + that.modules[modName].varName); if (typeOfString !== "undefined") { doSomething(); } The point is that the name of the var that I want to check for is in a string. Maybe it is simple but I don't know how. Edit: Thank you for the very interesting answers so far. I will follow your suggestions and integrate this into my code and do some testing and report. Could take a while. Edit2: I had another look at the

R: Knitr gives error for SQL-chunk

十年热恋 提交于 2019-12-23 16:53:51
问题 I would like to knit the output of my R-markdown, which includes a couple of SQL-chunks. However, if I start knitting, I get the error: Line 65 Error in eval(expr, envir, enclos) : object 'pp_dataset' not found Calls: <Anonymous> ... process_group.block -> call_block -> eval_lang -> eval Execution halted I have no clue what is going on, because if I just run this chunk (which starts at line 64) then it works fine. The chunk that starts at line 64 looks as follows: ```{sql, connection=con,

Why does the evaluation of a string defining a function return undefined instead of the function?

我们两清 提交于 2019-12-23 13:31:59
问题 function y(fct) { var a = 2; var fctStr = String(fct); var fct1 = eval(fctStr); console.log("fctStr=" + fctStr); // output: fctStr=function x() { return a + 1 } console.log("fct1="); console.log(fct1); // output: undefined. Why it is undefined? I expect fct1 is a function. return fct1(); // exception: undefined is not a function. } function x() { return a + 1 } y(x) // I expect it returns 3. However, it throws exception at above "return fct1()" statement. This code in Chrome will get fct1 as

What can I use instead of eval()?

若如初见. 提交于 2019-12-23 10:13:14
问题 I have a string that stores some variables that must be executed to produce a result, for example: define('RUN_THIS', '\$something.",".$somethingElse'); Which is then eval() -uated: $foo = eval("return ".RUN_THIS.";"); I understand that eval is unsafe if the string that gets evaluated is from user input. However, if for example I wanted to have everything run off Facebook's HipHop which doesn't support eval() I couldn't do this. Apparently I can use call_user_func() - is this effectively the

How to combine timeout and eval commands in bash

送分小仙女□ 提交于 2019-12-23 09:57:30
问题 For executing command that is stored in variable the eval command is used: └──> a="echo -e 'a\nb' | wc -l" └──> eval $a 2 But how can it be combined with timeout command? I've tried following which gives me wrong output: └──> timeout 10 $a 'a b' | wc -l And the following which gives me errors: └──> timeout 10 "$a" timeout: failed to run command `echo -e \'a\\nb\' | wc -l': No such file or directory └──> timeout 10 $(eval $a) timeout: failed to run command `2': No such file or directory └──>

PHP eval $a=“$a”?

走远了吗. 提交于 2019-12-23 08:30:12
问题 I was looking through some code for work, and came across this line: eval("\$element = \"$element\";"); I'm really confused as to why any PHP developer would've written this line. What purpose does this serve, besides setting a variable to itself? Luckily, the function this line is in is never called. 回答1: <?php $string = 'cup'; $name = 'coffee'; $str = 'This is a $string with my $name in it.'; echo $str. "\n"; eval("\$str = \"$str\";"); echo $str. "\n"; ?> The above example will output: This

How come eval doesn't have access to the scoped variables under a with statement?

大兔子大兔子 提交于 2019-12-23 08:26:59
问题 Why can't you access scoped variables using eval under a with statement? For example: (function (obj) { with (obj) { console.log(a); // prints out obj.a eval("console.log(a)"); // ReferenceError: a is not defined } })({ a: "hello" }) EDIT : As the knowledgeable CMS pointed out, this appears to be a browser bug (browsers that use the WebKit console). If anyone was wondering what abomination I was trying to come up with that would require both the "evil" eval and with -- I was trying to see if

Using `evaluate` function. Why it doesn't work?

为君一笑 提交于 2019-12-23 07:49:23
问题 This code: evaluate ("def test() { println \"Test is successful!\" }") test() results in exception: FATAL: No signature of method: script1409644336796288198097.test() is applicable for argument types: () values: [] Possible solutions: use([Ljava.lang.Object;), getAt(java.lang.String), use(java.util.List, groovy.lang.Closure), use(java.lang.Class, groovy.lang.Closure), wait(), wait(long) groovy.lang.MissingMethodException: No signature of method: script1409644336796288198097.test() is

Matlab function handle workspace shenanigans

佐手、 提交于 2019-12-23 07:39:29
问题 In short : is there an elegant way to restrict the scope of anonymous functions, or is Matlab broken in this example? I have a function that creates a function handle to be used in a pipe network solver. It takes as input a Network state which includes information about the pipes and their connections (or edges and vertices if you must), constructs a large string which will return a large matrix when in function form and "evals" that string to create the handle. function [Jv,...] =

[Python3 练习] 002 温度转换2

纵然是瞬间 提交于 2019-12-23 05:55:34
题目:温度转换 II (1) 描述 温度的刻画有两个不同体系:摄氏度 (Celsius) 和华氏度 (Fabrenheit) 请编写程序将用户输入的华氏度转换为摄氏度,或将输入的摄氏度转换为华氏度 转换公式如下,C 表示摄氏度,F 表示华氏度‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬ C = ( F - 32 ) / 1.8‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬ F = C * 1.8 + 32‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‬‭‬ (2) 要求‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬ 输入输出的摄氏度采用大写字母 C 开头,温度可以是整数或小数,如:C12.34 指 12.34 摄氏度