Editing
JavaScript/Notes/Scope
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Omitting var in VariableDeclaration== Assignment without var is not a variable declaration. <pre> foo = 1; </pre> The identifier foo must be resolved up the scope chain (see 11.13.1 Simple Assignment, also below). If foo is not found, a foo property is created on the global object (see 8.7.2 <code>PutValue</code>). This can cause further problems in IE with IE's global scope polluter. See: [https://groups.google.com/forum/#!msg/comp.lang.javascript/K3PD0gJgUxY/0R0OZvHs2K4J Extra Properties: The Element Id Resolver Object] <pre> 11.13.1 Simple Assignment (= ) The production AssignmentExpression : LeftHandSideExpression = AssignmentExpression is evaluated as follows: 1. Evaluate LeftHandSideExpression. 2. Evaluate AssignmentExpression. 3.Call GetValue(Result(2)). 4.Call PutValue(Result(1), Result(3)). 5.Return Result(3). </pre> Step 4 leads to <code>PutValue(foo, 1)</code> <pre> 8.7.2 PutValue(V, W) 1. If Type(V) is not Reference, throw a ReferenceError exception. 2. Call GetBase(V). 3. If Result(2) is null, go to step 6. 4. Call the [[Put]] method of Result(2), passing GetPropertyName(V) for the property name and W for the value. 5. Return. 6. Call the [[Put]] method for the global object, passing GetPropertyName(V) for the property name and W for the value. 7. Return. </pre> Step 2, <code>GetBase(v)</code> is <code>null</code>, so that leads to step 6. That leads to <code><nowiki>[[Put]]</nowiki></code> (foo, 1) on the global object. <pre> 8.6.2.2 [[Put]](P, V) When the [[Put]] method of O is called with property P and value V, the following steps are taken: 1. Call the [[CanPut]] method of O with name P. 2. If Result(1) is false, return. 3. If O doesn't have a property with name P, go to step 6. 4. Set the value of the property to V. The attributes of the property are not changed. 5. Return. 6. Create a property with name P, set its value to V and give it empty attributes. 7. Return. Note, however, that if O is an Array object, it has a more elaborate [[Put]] method (15.4.5.1). </pre> Note step 6: Create a property with name P, set its value to V and give it empty attributes. Global object properties (user-defined ones, at least) are <nowiki>[[Configurable]]</nowiki>, variables, global or otherwise, are not. User-defined properties are, by default, <nowiki>[[Configurable]]</nowiki>, which means that they can be deleted. If code is eval code, then let configurableBindings be true else let configurableBindings be false. http://www.ecma-international.org/ecma-262/5.1/#sec-10.5
Summary:
Please note that all contributions to Noisebridge are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
Noisebridge:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Log in
Request account
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Dig in!
Noisebridge
- Status: MOVED
- Donate
- ABOUT
- Accessibility
- Vision
- Blog
Manual
MANUAL
Visitors
Participation
Community Standards
Channels
Operations
Events
EVENTS
Guilds
GUILDS
- Meta
- Electronics
- Fabrication
- Games
- Music
- Library
- Neuro
- Philosophy
- Funding
- Art
- Crypto
- Documentation/Wiki
Wiki
Recent Changes
Random Page
Help
Categories
(Edit)
Tools
What links here
Related changes
Special pages
Page information