In yesterday's "Javascript Definitive Guide" Study Notes No. 10: ECMAScript 5 Enhanced Object Model article, a strange phenomenon occurred when debugging a piece of code. The source code is now posted below:
The result of running in Google:
http://img.blog.csdn.net/20140529073008296?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMTA0Mzg0Mw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity /Center
This result is correct, but if you change one place, the result will be different
Run result:
Why is this? I just changed a simple variable name
The problem lies in the name, but I am not familiar with JS and I don’t understand it. I searched for information on the Internet and found no results. Later I asked a senior brother for advice and he also changed the name. The question was posted on the forum: http://bbs.csdn.net/topics/390799744?page=1#post-397474060,
name is the window attribute, which is used to set or return the name and data of the window. Type is string. Because the first sentence is function Person(){}, it has ended, so the following code may be in the global context. That is to say, you think alert(JSON.stringify(name)); is the output var name above, but What may actually be output is window.name. As for the output [Object object], this type is the type of the value of name.
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn