Topic: Passing an array of objects argument in an eval statement Pages that link to <a href="https://ozoneasylum.com/backlink?for=26727" title="Pages that link to Topic: Passing an array of objects argument in an eval statement" rel="nofollow" >Topic: Passing an array of objects argument in an eval statement\

 
Author Thread
Maskkkk
Paranoid (IV) Inmate

From: Willaimsport, PA, US of A the hole i
Insane since: Mar 2002

IP logged posted posted 09-27-2005 00:06 Edit Quote

Is it possible to pass an array of objects as an argument in an eval statement in Javascript?


I've got an array that looks like:

data[n]
|
Object
|
Object
|
...

And I want to pass it to an eval statement.


If I'm completely out of my mind, let me know too.



- AIM: MASKKKK

01001101011000010111001101101011011010110110101101101011

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

IP logged posted posted 09-27-2005 04:53 Edit Quote

Generally speaking, 99% of the time, when you're using eval() you're doing something wrong. What is it you're trying to accomplish?

I don't really understand your array picture.


 

Maskkkk
Paranoid (IV) Inmate

From: Willaimsport, PA, US of A the hole i
Insane since: Mar 2002

IP logged posted posted 09-27-2005 13:23 Edit Quote

Well I guess what I'm trying to do is *ahem* abstract out some functionality (yes I know JS does not actally support this), but I'm making a component of sorts and I've added some extra non-standard not in the DTD tags into the mix. (yes, a-list-apart also said these were uncharted waters...) but the article they had on it was about the only way I could do what I needed to do.

I added some new attributes (that I made for my own purposes) to an <input ..> tag (textbox), these specify two functions which (right or wrong) have to be called by eval statements, when communicating back with the server. The first JS function uses DWR (Direct Web Remoting)(A.K.A. Ajax) to call the server, and this in-turn calls the server returns the data and calls the second JS function (which is more or less the abstract one) passing the data to it.

However on the second function call that recieves the data has a bit of functionality that I'd like to encapsulate so that the programmer using the component doesn't have to worry about writting that code himself. And this is why I need to pass the array I described above into an eval statement. So that the programmer doesn't have the freedom to bother with how the component works, but does have the freedom to use the data returned from the server however he/she sees fit.



- AIM: MASKKKK

01001101011000010111001101101011011010110110101101101011

DmS
Maniac (V) Inmate

From: Sthlm, Sweden
Insane since: Oct 2000

IP logged posted posted 09-27-2005 20:28 Edit Quote

Home made attributes in a form element can be reached by js just as any other attributes.

Grab the element by myElem = getElementByID('my_id') then you should be able to just do myElem.myHomeMadeAttribute to access it.

Do you still need the eval if you grab them like that?

xcuse any syntaxerrors, no time to check now.

/Dan

{cell 260} {Blog}
-{Proudly running OSX, Debian, WXP, W98, well not so proudly on the last 2...}-
-{ ?There are two major products that come out of Berkeley: LSD and UNIX. We don't believe this to be a coincidence. - Jeremy S. Anderson" }-
-{"Light travels faster than sound. This is why some people appear bright until you hear them speak.?}-

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

IP logged posted posted 09-27-2005 20:29 Edit Quote

That still doesn't really explain the eval I haven't used that in 5 years.

Do you want to do something like this:

<input name="foo" onsomething="newFunc()" />

where the user can name "newFunc()" whatever they want and it will get passed the returned Data Object?

Because you could do that like so:

do = whatever // My returned data stuff.

f = document.forms.formName.elements.foo.onsomething;
f( do );



.:[ Never resist a perfect moment ]:.

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

IP logged posted posted 09-30-2005 06:20 Edit Quote

Heh, I always reply to these things and then forget about them until days later.

I don't really understand your description. It sounds like you have two uses for eval, the first being taking a function name and calling the function. I believe this will work for that (though it's untested):

functionname = "myfunction"; // get this however you want
window[functionname](arguments);
// same as window.myfunction(arguments), same as myfunction(arguments)

I don't understand the rest of your description. You keep using the phrase "pass the array into an eval statement," which doesn't make much sense. Eval takes a string and evaluates it as code; if you already have an array, why turn it into a string just so you can use eval to turn it back into an array?

What sort of data are you trying to convert here?


 



Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu