1

I have a Prototype class which has a function removeMarker.

var Location = Class.create({
    removeMarker: function(){
        // Some code here to remove a marker from a map
    }
});

I have an array of these:

var locations = [];

Is there an easy way to invoke removeMarker() on every location object in the array?

At the moment I am using:

locations.each(function(l,i) {
    l.removeMarker();
});

I am sure I have seen something using .map() or .invoke() but running

 locations.invoke(removeMarker);

doesn't seem to work. I know I am just doing something stupid, just need someone to point it out...

4
  • 1
    each and invoke are definitely not native JavaScript methods. I don't understand what your question has to do with prototypes and enumerable properties. Commented Aug 11, 2011 at 11:09
  • @FelixKling: question title. "Prototype" offers/extends boths methods. Commented Aug 11, 2011 at 11:16
  • @jAndy: Oh... I was too much thinking about, you know, prototype inheritance... nvm. Thanks! Commented Aug 11, 2011 at 11:29
  • Sorry felix, should have said I was using Prototype framework! Commented Aug 11, 2011 at 15:10

1 Answer 1

2

Try adding removeMarker between apostrophes.

So: locations.invoke('removeMarker');

Sign up to request clarification or add additional context in comments.

Comments

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.