473,748 Members | 7,571 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 1488
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
8202
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
1482
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
2277
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
2118
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
2138
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
7349
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
1652
by: santel_helvis | last post by:
Hi, Here is my code. function CallDisplay() { nodeobj=new mynode(); x="displayId("+nodeobj+")"; eval(x);
11
2003
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
2092
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
8991
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9247
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
6074
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
4606
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
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3313
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2783
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.