Creating an existing function... another stupid question?

Hoi javascripters,

I came across Marijn’s helper function again called forEach. It does just what it sounds like it does, and is one of those things one would consider adding to their own personal little library like getElementsByClassName…

My question is, I’ve heard/seen that Mozilla (and only Mozilla at this point) indeed HAVE a forEach function, and I do most of my beginning testing in a recent-stable Mozilla browser, so I’m not 100% sure but I think the Mozilla forEach might work… what happens if I write my own and I keep the name?

So if there’s some default forEach that the browser natively understands, and then I have a function in my lib that has the same name, does mine take precedence over the native one, or not? Is it just safer giving libraries slightly weird names so new in-built functions can’t possibly interfere?

So also, if later browsers end up implementing the newer Javascript (2?) that as I hear, will implement a getElementsByClassName, would this break, or ignore, everyone’s pre-made getElementsByClassName, assuming they are called the same name?

It should work the same for built-in methods as user-created methods… you can always override, and the last definition of the function is the one that will be used.

k thanks a lot. I read multiple times about how it goes with variables but never saw what is was for functions precisely.