473,699 Members | 2,278 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

eval(arguments) doesn't seem to be valid.

kovik
1,044 Recognized Expert Top Contributor
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 array through a callback (function). It's layout is:

ArrayMap: function(callba ck, array [, arg1 [,...]]);

If it wasn't for the need of extra arguments, I'd simply use forEach(). My attempt to pass the optional arguments from ArrayMap to the callback was to join them together with commas and eval() them into the callback call. It doesn't work though. Here's a very simplified example of what I mean:

Expand|Select|Wrap|Line Numbers
  1. function Test(a, b, c)
  2. {
  3.     alert('Length: ' + arguments.length + ', arguments[1]: ' + arguments[1]);
  4. }
  5. Test(1, eval('2, 3'));
The alert box will say "Length: 2, arguments[1]: 3".

Anyone know how I'd accomplish what I'm after? Oddly, I can't find any resources describing using eval() within a function call.
Jul 4 '07 #1
3 1482
gits
5,390 Recognized Expert Moderator Expert
hi ...

try the following ... i hope this is what you need ;)

Expand|Select|Wrap|Line Numbers
  1. function Test(a, b, c) { 
  2.     alert('Length: ' + arguments.length + ', arguments[1]: ' + arguments[1]);
  3. }
  4.  
  5. Test.apply(this, [1].concat(eval('[2, 3]')));
  6.  
kind regards
Jul 4 '07 #2
kovik
1,044 Recognized Expert Top Contributor
You know, I never even looked at the documentation for the apply method before. That's fantastic!

They don't call you Expert for nothing ;)
Thank you. ^_^
Jul 4 '07 #3
gits
5,390 Recognized Expert Moderator Expert
thank you the same goes for you ... glad to be able to help you ... the apply and call methods are real cool when developing oo-javascript ... because you may handle the scope really simple ...

kind regards
Jul 4 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

12
8185
by: lawrence | last post by:
I have a string which I want to send to eval(). How can I test it ahead of time to make sure it is valid code? I don't want to send it to eval and get parse errors. I want to do something like this: $valid = checkPHP($string); if ($valid) { eval($string); } else { $resultsObject->addToErrorResults("We wanted to send our template to eval(), but the PHP it contained was invalid.");
6
1481
by: Leif K-Brooks | last post by:
In Python 2.4, although None can't be directly assigned to, globals() can still be; however, that won't change the value of the expression "None" in ordinary statements. Except with the eval function, it seems: Python 2.4 (#2, Dec 3 2004, 17:59:05) on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> print None None
7
2273
by: steveneill | last post by:
Is this an alternative to eval(). Admittidly, I have done *very* little testing (ran it a few times in Firefox), but it seemed to work suprisingly well with simple expressions such as "alert('hello')" function _eval(s) { var h = document.getElementsByTagName("HEAD"); var o = document.createElement("SCRIPT"); o.text = s; h.appendChild(o);
6
2112
by: Roebie | last post by:
Hi everyone, I'm having some weird problem with evaluating the continue statement. Within a for loop I'm trying to evaluate a string (generated somewhere earlier) which basically has the continue statement in it. IE6 seems to have major problems with that as it generates an error "Can't have 'continue' outside of loop". Does anyone know why and/or have a workaround? I haven't tried any other browser since this one is the only one...
1
2135
by: Maaty | last post by:
I'm using a variable called: "cellalign" to specify the alignment based on the current context language. "cellalign" is located in the base class of all controls I use. Most of my controls work right. However some controls don't. That's; when I use the code: <td align='<%#cellalign%>'> The result is:
4
7344
by: CharlesA | last post by:
a general question... I'm a bit mystified by Databinder.eval(object, Colname, ) if controls can be bound to their individual data sources within the load event of the page... why would we ever use this quite inelegant OO code wrapped in #<% %> inside the markup? secondly: sometimes you see simliar code inside the markup without calls to
8
1650
by: santel_helvis | last post by:
Hi, Here is my code. function CallDisplay() { nodeobj=new mynode(); x="displayId("+nodeobj+")"; eval(x);
11
1995
by: C.W.Holeman II | last post by:
I am looking for an example using the object argument to eval(). http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Functions:eval -- C.W.Holeman II | cwhii@Julian5Locals.com-5 http://JulianLocals.com/cwhii To only a fraction of the human race does God give the privilege of earning one's bread doing what one would have gladly pursued free, for passion. I am very thankful. The Mythical Man-Month Epilogue/F.P.Brooks
4
2088
by: Mark | last post by:
Eval() doesn't seem to recognize the r'string' format. Is there a way around this. Example: If I input: ---------eval("r'C:\tklll\ndfd\bll'") I get the output: Traceback (most recent call last): File "<pyshell#3>", line 1, in <module> eval("r'C:\tklll\ndfd\bll'") File "<string>", line 1
0
8618
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9178
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8885
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7752
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6534
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5875
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4376
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2348
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.