ecmascript-5

How to explain object references in ECMAScript terms?

≡放荡痞女 提交于 2019-11-27 05:15:19
Consider this: var a = {}, b = a; In terms of the spec, b = a boils down to PutValue(b, GetValue(a)) , right? And GetValue(a) uses GetBindingValue("a", strictFlag) abstract operation, which returns "the value" in a . And "the value" is "the object" originally assigned to a . Then "the object" is stored in b , just like any other value would. But what is "the object" precisely? Where does the specification say that values of the Object type behave differently than primitives? Is it only that primitives are immutable, and objects are mutable? I'm asking because we always talk about "object

What really is a declarative environment record and how does it differ from an activation object?

雨燕双飞 提交于 2019-11-27 04:21:18
问题 Okay, so I lately have been reading about ES-5 lexical environment scope and I am not sure if I really understand what is going on with how variables are stored in EcmaScript. I did some research but it didn't clarified my information, only brought me up to two questions. So there they are: The first one is about ES-3 activations objects / variable objects . After reading ES-3 Specification and some sources on the Internet I can assume that they are just normal object, for example like those

Why is delete not allowed in Javascript5 strict mode?

两盒软妹~` 提交于 2019-11-27 04:10:21
I'm fairly new to javascript, but I'm in love with it's dangerously fast and loose expressiveness. That said, I noticed that apparently when operating in "use strict" mode, you can't delete objects. I'm not a huge fan of deleting things (since, in theory, scope should take care of that anyway), but I wonder what was the motivation behind removing this feature? The delete statement is still allowed in strict mode, but some particular uses of it are erroneous. It's only allowed for object properties, not simple names, and only for object properties that can be deleted. Thus var a = {x: 0};

Do reserved words need to be quoted when set as property names of JavaScript objects?

送分小仙女□ 提交于 2019-11-27 03:51:14
问题 Given an object literal, or jQuery(html, attributes) object, does any specification state that reserved words, or future reserved words MUST be quoted? Or, can, for example, class be set as a property name of an object without using quotes to surround the property name, without the practice being contrary to a specification concerning identifiers, property names, or use of reserved words? Seeking a conclusive answer as to this question to avoid confusion. let objLit = { class: 123, var: "abc"

Object.keys() complexity?

微笑、不失礼 提交于 2019-11-27 03:45:44
问题 Anyone know the time-complexity of ECMAScript5's Object.keys() in common implementations? Is it O(n) for n keys? Is time proportional to the size of the hash table, assuming a hash implementation? I'm looking for either guarantees by language implementors or some real world benchmarking. 回答1: It appears to be O(n) in V8 (chrome, node.js) at least: > var hash = {} > , c = 0; > > var s = +new Date();Object.keys(hash);console.log(+new Date() - s); 0 > for(var i=0; i<100000; i++, c++){ hash[c] =

Math.pow with negative numbers and non-integer powers

醉酒当歌 提交于 2019-11-27 03:29:26
问题 The ECMAScript specification for Math.pow has the following peculiar rule: If x < 0 and x is finite and y is finite and y is not an integer, the result is NaN. (http://es5.github.com/#x15.8.2.13) As a result Math.pow(-8, 1 / 3) gives NaN rather than -2 What is the reason for this rule? Is there some sort of broader computer science or IEEEish reason for this rule, or is it just a choice TC39/Eich made once upon a time? Update Thanks to Amadan's exchanges with me, I think I understand the

Node.js Global eval, throwing ReferenceError

可紊 提交于 2019-11-27 02:26:43
问题 I am trying to learn JavaScript from the Rhino book. I was trying to execute the following code from the book with regards to eval() . I am using node.js (v0.10.29) to execute the examples. var geval = eval; // aliasing eval to geval var x = 'global'; // two global variables var y = 'global'; function f () { var x = 'local'; // define a local variable eval('x += "changed";'); // direct eval sets the local variable return x; } function g () { var y = 'local'; // define a local variable geval(

Why do catch clauses have their own lexical environment?

百般思念 提交于 2019-11-27 02:06:47
Consider the following excerpt from ECMA-262 v5.1 (which I recently saw in this question ): A Lexical Environment is a specification type used to define the association of Identifiers to specific variables and functions based upon the lexical nesting structure of ECMAScript code. A Lexical Environment consists of an Environment Record and a possibly null reference to an outer Lexical Environment. Usually a Lexical Environment is associated with some specific syntactic structure of ECMAScript code such as a FunctionDeclaration, a WithStatement, or a Catch clause of a TryStatement and a new

Why doesn't an octal literal as a string cast to a number?

断了今生、忘了曾经 提交于 2019-11-27 01:38:37
问题 In JavaScript, why does an octal number string cast as a decimal number? I can cast a hex literal string using Number() or + , why not an octal? For instance: 1000 === +"1000" // -> true 0xFF === +"0xFF" // -> true 0100 === +"0100" // -> false - +"0100" gives 100, not 64 I know I can parse with parseInt("0100" [, 8]) , but I'd like to know why casting doesn't work like it does with hex and dec numbers. Also, does anyone know why octal literals are dropped from ECMAScript 5th Edition in strict

WeakMap implementation in EcmaScript5?

我的未来我决定 提交于 2019-11-27 01:19:17
问题 I've run across a JavaScript library that implement a cross-browser WeakMap in ES5 . (WeakMap is slated for ES6 .) How can this possibly work without support in the JavaScript language itself? Edit: Just to be clear, I'm referring to a Weak Map, not a regular Map. I tested this project out using Chrome's profiler and the keys are not held by strong references. They get GC'ed without having to remove them from the WeakMap. 回答1: It took me a while to grok the code, but then it hit me: the key