1

I have an array of div names, the div of which I would like to switch off on loading.

I read from both prototype api and another website that invoke is generally preferred if one is to do the same thing to each of the items in a list.

//I have this switch_off function

function switch_off(div){
  Effect.SwitchOff(div);
}

//and this array
div_names = ['notice','status_bar','word_count']

//Please do tell me if this is not the best option:
div_names.invoke('switch_off');

But it doesn't work.

Is there another parameter I need to supply to invoke? Could it be this?

Added: Here's the Firebug output

//value[method] is undefined
//[Break on this error] return value[method].apply(value, args); 

Thank You!

1 Answer 1

1

The effect of invoke is to call a member method on each of the items in the enumerable and as such is not suited for the type of result you are trying to achieve unless you want to extend the prototype of string.

Something that should provide to be working would be any of the following:

function switch_off(div){
  Effect.SwitchOff(div);
}    

//and this array
div_names = ['notice','status_bar','word_count'];

//Please do tell me if this is not the best option:
div_names.each(switch_off);

or

['notice','status_bar','word_count'].each(function (div){
    Effect.SwitchOff(div);
});
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks Quintin, It didn't do the alert. I included Firebug output that might help
@Nik wow, it's been a LONG time since I've used prototype and misinterpreted the documentation, the effect of invoke is to call a member method on each of the items in the enumerable. So in your instance it will never work. I will update a reasonable solution.
Just curious, what do you use instead of prototype now or do you not program much in js anymore?
@Nik I do still use javascript, I am a big fan of the language actually. When I use a ready made library my preference is jQuery it's a very elegant library but a departure from prototype for sure.
@Quitin I see. I am thinking about switching, too, as Prototype hasn't been updated for 3 years? until recently. Thanks again!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.