Hey Joker,

A method is just a property of an object.  You can access any property
using either dot notation (i.e.: foo.property) or square brackets
(i.e.: foo[property]).  So you could do this:

foo.myMethod(); // common way to call the method

var methName = 'myMethod';
foo[methName](); // call with method name in a variable.

In your circumstances I would skip this and use an iterator to loop
through your array instead of a for loop.  Prototype offers a number
of iterators optimized for specific uses.  I would use the "invoke"
iterator: http://www.prototypejs.org/api/enumerable/invoke

In your example you could do this:
myArr.invoke('coolFunction', 'Hello World').

Notice that doing it this way you don't have to pass "Hello World" in
two sets of quotes like you do in the example below.  This iterator
has the benefit that the code is smaller and more readable.  It also
has the added benefit that it can pass non-string arguments to the
method being called.

In this situation $F wouldn't help because you aren't dealing with
form fields.

--
Ben

On May 13, 8:05 am, ferion <fer...@gmx.de> wrote:
> Hi everybody,
>
> i got a working function which fires a method on all objects (classes)
> with given parameters.
>
> Simplified i'm using the following code
>
> myClass = new Class(
> {
>       coolFunction: function (arg)
>       {
>            alert(arg);
>       }
>
> });
>
> myArr[0] = new myClass();
> myArr[1] = new myClass();
>
> function fireArrayObjectsFunctions(funcName,myArgs)
> {
>     for (var i=0; i<myArr.length;i++)
>     {
>        var callString = "myArr["+i+"]."+funcName+"("+myArgs+")";
>        eval(callString);
>    }
>
> }
>
> fireArrayObjectsFunctions('coolFunction','"Hello World"');
>
> This sort of works but i want to get rid of the evalfunction an the
> stringhandling.
> Anybody got an Idea how to solve this wis $F or other
> prototypefunction?
>
> Thanks
> Joker
>
> P.S.
> Please excuse my lack of proper english.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to