Home > Web Front-end > JS Tutorial > Introduction to examples of conflicting meanings of names in JavaScript_javascript skills

Introduction to examples of conflicting meanings of names in JavaScript_javascript skills

WBOY
Release: 2016-05-16 16:46:31
Original
1232 people have browsed it

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:

Copy code The code is as follows:



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
Copy the code The code is as follows:



Run result:
Introduction to examples of conflicting meanings of names in JavaScript_javascript skills
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.
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template