English 中文(简体)
Java印功能反向操作
原标题:Inverse operation for Javascript s Function.toString()
  • 时间:2011-10-16 01:55:08
  •  标签:
  • javascript

Java印申请 我需要能够让用户拯救物体的状况。 这需要节省以前通过全球倡议或通过全球倡议创造的一套习惯功能,并在晚些时候装载这些储存的功能。 基本上,我需要编辑和编辑职能。

现在,我通过使用功能标语......toString(......)方法实现序列化:

func.toString().replace( " ,  " ).replace(/(
)/g,    ).replace(/(
)/g,    ).replace(/(	)/g,    )

这使我具有像这一美丽的“航空”职能(指出职能没有名称):

"function (someParameter) {this.someFunctionName(return  something ;}"

这是我斗争的领域。 我目前最妥善的办法,就是使各项职能民主化:

var func = eval(  t =  +  so.actions[i].func);

Note how I prepend the serialized function with t = before calling eval() on it. I don t like doing this because it creates a global variable but I cannot find a way around it. When not prepending this, I receive a "SyntaxError: Unexpected token (". When prepending var t =, eval() does not return the function but undefined.

是否有替代的“统一”功能?

PS:我知道在用户投入上使用电子数据对安全的影响。 在可预见的未来,我是唯一使用这一软件的人,因此,目前这是一个非问题。

最佳回答

您可以利用功能构造避免形成全球变量:

var func = Function("return " + so.actions[i].func)();

This is equivalent to:

var func = eval("(function () { return " + so.actions[i].func + " })()");

值得警告的是,你所赢得的近似封锁能够抓住,因此,当你序列化和脱射时,功能内的变数将“改变”。

<><>>>

我不认为,你当然可以做:

var func = eval("(" + so.actions[i].func + ")");
问题回答

这一工作应当:

eval( var func =   + so.actions[i].func);




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签