eval

JavaScript学习笔记三-数组

偶尔善良 提交于 2019-12-10 16:54:39
eval命令 eval命令 接受一个字符串 作为参数,并将这个字符串当作语句执行。 eval('var a = 1;'); a // 1 放在eval中的字符串, 应该有独自存在的意义 ,不能用来与eval以外的命令配合使用。举例来说,下面的代码将会报错。 如果eval的参数不是字符串,那么会原样返回。 eval ( 123 ) // 123 eval没有自己的作用域 ,都在当前作用域内执行,因此可能会修改当前作用域的变量的值,造成安全问题。 var a = 1; eval('a = 2'); a // 2 JavaScript 规定,如果使用严格模式,eval内部声明的变量,不会影响到外部作用域。 ( function f ( ) { 'use strict' ; eval ( 'var foo = 123' ) ; console . log ( foo ) ; // ReferenceError: foo is not defined } ) ( ) 上面代码中, 函数f内部是严格模式,这时eval内部声明的foo变量,就不会影响到外部。 不过,即使在严格模式下,eval依然可以读写当前作用域的变量。 ( function f ( ) { 'use strict' ; var foo = 1 ; eval ( 'foo = 2' ) ; console . log ( foo

A better way than eval() when translating keyword arguments in QuerySets (Python/Django)

你离开我真会死。 提交于 2019-12-10 16:39:18
问题 I'm using django-transmeta (couldn't get anything else working better with django 1.2.5) which creates several columns in a table like: content_en, content_es, content_it Before implementing i18n I had: items = Items.objects.filter(categories__slug=slug) now category.slug is internationalized therefore I have "category.slug_en", "category.slug_es", "category.slug_it" and so on. So I though of doing: from django.db.models import Q from django.utils.translation import get_language current_lang

Looking for eval function in any .NET language

前提是你 提交于 2019-12-10 16:02:14
问题 Do any .NET/CLR languages support an eval function and also allow calling into standard .NET code (e.g. calling into C# code)? I know that neither F# nor C# support eval . Are there any other options? I am ideally looking for a solution compatible with .NET 3.5 (so I think this rules out Clojure-CLR), but I'm interested in any/all options. 回答1: JScript.NET has an eval function, see this answer 回答2: An Eval Function for C# using JScript.NET (JavaScript) 回答3: Not sure if this helps, but as you

js中的eval函数

瘦欲@ 提交于 2019-12-10 15:50:59
eval是一个函数,js的设计者将它变成类似运算符 eval的作用是什么呢? **它使用了调用它的 变量作用域环境** 举个简单的例子 function fn(){ eval("var a=1;") console.log(a)//它会改变局部变量的值 并且也可与生明一个新的局部变量 } fn() 全局eval():此函数可以通过别名去定义,当通过别名定义时,会改变全局的代码变量 而不会修改到局部变量的值 var newEval=eval,a=1; function fn(){ var a=5; newEval("a=2;"); return a; } var value=fn(); console.log(value,a)//5,2 来源: CSDN 作者: 你的瑞瑞〰 链接: https://blog.csdn.net/wang9rui/article/details/103475807

eval a list into a let on clojure

笑着哭i 提交于 2019-12-10 15:46:26
问题 My problem is the next, i try to evaluate a list with some vars using a let to asign values to this vars if i do (def a (list * 'x 'y)) and (let [x 3 y 3] (eval a)) I have a CompilerException java.lang.RuntimeException: Unable to resolve symbol: x in this context, compiling:(NO_SOURCE_PATH:6) but if I run (def x 4) (def y 4) and (eval a) i have a 16, anyway if I run again (let [x 3 y 3] (eval a)) again I have 16, exist a method to binding the x and y correctly and eval the list? ty! 回答1: Well

javascript eval() and security

旧街凉风 提交于 2019-12-10 15:44:05
问题 developer.mozilla.org says: Don't use eval needlessly! eval() is a dangerous function, which executes the code it's passed with the privileges of the caller. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval Any malicious user can turn on chrome debugger for example, and modify javascript code that is being executed. So he can put his own functions to be executed etc. Is there such thing as "secure javascript code" in general? 回答1: Any malicious user can

Can I call methods with variables?

杀马特。学长 韩版系。学妹 提交于 2019-12-10 15:26:21
问题 Can I do the following in PHP? $lstrClassName = 'Class'; $lstrMethodName = 'function'; $laParameters = array('foo' => 1, 'bar' => 2); $this->$lstrClassName->$lstrMethodName($laParameters); The solution I'm using now, is by calling the function with eval() like so: eval('$this->'.$lstrClassName.'->'.$lstrMethodName.'($laParameters);'); I'm curious if there is a beter way to solve this. Thanks! 回答1: You don't need eval to do that ... depending on your version Examples class Test { function

How can I use vim regex to replace text when math divide is involved in the expression

左心房为你撑大大i 提交于 2019-12-10 15:19:24
问题 I am using vim to process text like the following 0x8000 INDEX1 .... 0x8080 INDEX2 .... .... 0x8800 INDEXn .... I want to use regular expression to get the index number of each line. that is 0x8000 ~ 0 0x8080 ~ 1 .... 0x8800 ~ n The math evaluation should be (hex - 0x8000) / 0x80. I am trying to using vim regular expression substitution to get the result in line %s/^\(\x\+\)/\=printf("%d", submatch(1) - 0x8000) This will yield 0 INDEX0 128 INDEX1 .... 2048 INDEXn What I want to do is to

Do the math sum of a text variable? (E.g 5865/100 )

孤人 提交于 2019-12-10 14:39:52
问题 I have a variable that is... $whatever = "5865/100"; This is a text variable. I want it to calculate 5865/100 , so that I can add it to other numbers and do a calculation. Number_format doesn't work, as it just returns "5,865". Whereas I want it to return 58.65 I could do... $explode=explode("/",$whatever); if(count($explode)=="2") { $whatever = $explode[0]/$explode[1]; } But it seems rather messy. Is there a simpler way? 回答1: Evaluate as PHP expression, but first check if it contains only

AS3 - evaluating at runtime - D.eval vs hurlant

邮差的信 提交于 2019-12-10 14:37:23
问题 I need to pass in a string that gets evaluated at runtime. So I can write this: var foo = someEvalMethod ( "dataObject.someValue" ) instead of: if ( argIn == "dataObject.someValue") var foo = dataObject.someValue } Does anyone have an opinion on the following evaluate libraries, or better ones for AS3? Thanks: AS3 eval by hurlant: http://eval.hurlant.com/ D.eval by RIA 1: http://www.riaone.com/products/deval/ 回答1: As far as I know AS3 eval by hurlant is a "real" compiler. It parses code,