It's not a reserved word, and it's not a clash with window.name
. There are problems with using a window
property name as a global variable in IE, but it's OK as long as you have declared them globals using the var
or function
keywords as you have here.
What you have here is a strange—and, as far as I can see, undocumented—IE quirk (copied by WebKit) where, in event handlers declared via inline attribute, the properties of the target element are treated as local variables. This is presumably so you can write code like:
<input name="foo" value="bar" onclick="alert(name+': '+value)"/> // foo: bar
'cos saying this.name
is too hard, apparently. Once again IE trying to be “convenient” causes weird unpredictable bugs.
This is just another reason not to use inline event handler attributes. Without them:
<input id="doit" type="button" value="Do it"/>
<script type="text/javascript">
document.getElementById('doit').onclick= function() {
name('bob');
};
</script>
works fine.