473,411 Members | 2,083 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

eval(function) doesn't work on IE

I need to call a function inside another function, but I don't know the
function name.
I solved in this way:

function x (newFunc)
{
eval(newFunc+ "()");
}

Again this work for Firefox and other browser, but not in IE. Any idea
on how to solve this?

Thanks
Andrew

Dec 12 '06 #1
3 6347

Andrew wrote:
I need to call a function inside another function, but I don't know the
function name.
I solved in this way:

function x (newFunc)
{
eval(newFunc+ "()");
}

Again this work for Firefox and other browser, but not in IE. Any idea
on how to solve this?
Your use of eval is completely unnecessary. If you are passing a
reference to your function, you may invoke it directly. For example:

function x(fnc_ref)
{
fnc_ref();
}

function y()
{
//...etc.
}

x(y);

Dec 12 '06 #2
In comp.lang.javascript message
<11*********************@l12g2000cwl.googlegroups. com>, Tue, 12 Dec 2006
14:42:10, web.dev <we********@gmail.comwrote:
If you are passing a
reference to your function, you may invoke it directly. For example:

function x(fnc_ref)
{
fnc_ref();
}
And if you need the name of the current fnc_ref within function x,
Str = fnc_ref.toString().match(/function\s+(\w+)\W/)[1]
will do it for reasonably-named functions in at least some browsers.

For the general case, improve the RegExp.
Query : is there nowadays a respectable means XXXX of getting a
reference to a function given only its name ?

e.g. ISNAN == XXXX("isNaN")

Of course, XXXX being eval should do it; could that be deemed an
acceptable use, or is there a more specific alternative?

It's a good idea to read the newsgroup and its FAQ. See below.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
<URL:http://www.jibbering.com/faq/ Old RC FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Dec 13 '06 #3
Dr J R Stockton said the following on 12/13/2006 1:10 PM:
In comp.lang.javascript message
<11*********************@l12g2000cwl.googlegroups. com>, Tue, 12 Dec 2006
14:42:10, web.dev <we********@gmail.comwrote:
> If you are passing a
reference to your function, you may invoke it directly. For example:

function x(fnc_ref)
{
fnc_ref();
}

And if you need the name of the current fnc_ref within function x,
Str = fnc_ref.toString().match(/function\s+(\w+)\W/)[1]
will do it for reasonably-named functions in at least some browsers.

For the general case, improve the RegExp.
Query : is there nowadays a respectable means XXXX of getting a
reference to a function given only its name ?

e.g. ISNAN == XXXX("isNaN")

Of course, XXXX being eval should do it; could that be deemed an
acceptable use, or is there a more specific alternative?
If XXXX is a function name defined like any other, then window['XXXX']()
will call that function.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 14 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: robcarlton | last post by:
hi everybody I've written this function to make a list of all of an objects attributes and methods (not for any reason, I'm just learning) def list_members(obj) l = dir(obj) return map(lambda...
3
by: Craig | last post by:
First of all, this one is driving me crazy, so thanks in advance for any help!! I've got a javascript function in a parent document that generates an HTML document on the fly when a button is...
7
by: J. Hall | last post by:
Hi dudes, Got a simple webpage, with three numeric text input boxes, the idea being that the user is asked to insert percentages of their business around the world... UK, Europe, Other ...
4
by: tozeina | last post by:
Can any one help in this please. I'm using eval function in JavaScript, But when the eval method return a big big number the result will be a number with "E" for example :...
2
by: - | last post by:
i am using a regular expression in a select statement inside a function. how do i dynamically insert a variable into the regexp? eg. SELECT string ~ '\\d{X}' where X is the dynamic variable....
1
by: shalini jain | last post by:
Hi, I am facing the problem with eval function. I want to know how to pass a function in eval() when we have to create the function itself. I would better explain my problem with the help of an...
8
by: sonet | last post by:
Many Language have eval function.The C have eval function? How to execute c code in c ? Can i execute c code from a variable(like perl's code ref)? Or i must do this job by using yacc & lex ? All...
3
kovik
by: kovik | last post by:
I'd like to pass arguments from one function to another, but I can't seem to get it through my head to make it work. I wrote a function similar to PHP's array_map(), which runs all members of an...
6
by: RandomElle | last post by:
Hi there I'm hoping someone can help me out with the use of the Eval function. I am using Access2003 under WinXP Pro. I can successfully use the Eval function and get it to call any function with...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.