问题
In the Chrome Developer Tools window, I typed in:
> name = ["a", "b", "c"]
["a", "b", "c"]
However, name
became a string:
> typeof name
"string"
> name
"a,b,c"
> name[1]
","
This obviously isn't true for other variable names!
> foo = ["a", "b", "c"]
["a", "b", "c"]
> typeof foo
"object"
> foo[1]
"b"
And name
is defined as the empty string on page load (and, as far as I can tell, cannot become anything other than a string).
So, what's up with name
?
回答1:
When you type name
you are implicitly referencing window.name
, which according to MDN:
Gets/sets the name of the window.
https://developer.mozilla.org/en-US/docs/Web/API/window.name
来源:https://stackoverflow.com/questions/19008645/whats-special-about-the-name-variable-in-javascript