Sunday, January 20, 2008

Eval function in JavaScript

Again I am writing some programming thing on this blog after a longtime.

Eval(eval()) function is an advanced function in javascript which may look silly and most people may overlook it, but it is a really a powerful thing that javascript provides.

We had a scenario where we have to pass the applet object dynamically so that we can manipulate its param.

document.appletName.getChartObject().getTitle());

where appletName is a variable which stores appletname. So we started banging our heads on that. First option was creating an array variable to store the applets. But that would be too complicated. Then I came across this function.

So we used

eval("document."+appletName+".getChartObject().getTitle()");

and tadaaaah...We got the desired result.

The eval() function evaluates a string and executes it as if it was script code. Cool na...

 

Technorati Tags: ,,

No comments:

Post a Comment

Featured Post

Domain and blog for Sale