ecmascript-5

Math.pow with negative numbers and non-integer powers

早过忘川 提交于 2019-11-30 13:02:28
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 reasoning now. I would like to expand upon our discussion for the sake of posterity. Let's take the

Motive behind strict mode syntax error when deleting an unqualified identifier?

若如初见. 提交于 2019-11-30 11:34:48
问题 I'm having trouble understanding why, in strict mode, a syntax error occurs when delete is used on an unqualified identifier. In most cases, it makes sense... if you are declaring variables in the usual way with the var keyword, and then trying to use delete on them, in non-strict mode it would silently fail, so it makes sense for strict mode to fail with an error in those cases. However, there are cases where you can't delete identifiers that are qualified: (function() { // "use strict"; var

Can I get an unbound function from a bound function in JavaScript?

不想你离开。 提交于 2019-11-30 11:27:10
问题 I'm getting my head wrapped about currying and other techniques using Function.prototype.bind. It seems extremely useful to change function scope (i.e., this value) in certain situations. However it looks like you can't change the scope with bind once you already did so: function f = obj.method.bind(42); function g = obj.method.bind('Hi'); function f2 = f.bind('Hi'); // “this” is still 42 Is it possible to retrieve the original unbound function from a bound function at all? 回答1: What the bind

How to force google closure compiler to keep “use strict”; in the compiled js code?

孤者浪人 提交于 2019-11-30 11:21:18
问题 If you're using the module pattern and have something like this: (function () { "use strict"; // this function is strict... }()); and compile the code using the Google Closure Compiler, the "use strict"; directive will not make it into the compiled file. So how do you prevent the Closure Compiler from removing the ES5/strict directive? (Note that I don't want to use the other mode of enforcing ES5/strict mode, which is to simply add the "use strict"; to the first line of the compiled file. I

Which (javascript) environments support ECMAscript 5 strict mode? (aka “use strict”)

▼魔方 西西 提交于 2019-11-30 10:56:35
问题 ECMAScript 5 is in its final draft as I write this; It is due to include a strict mode which will prevent you from assigning to the global object, using eval, and other restrictions. (John Resig's Article is a good introduction.) This magical sanity-saving mode is triggered by including the string "use strict" at the top of your file (or function.) However, in older environments, "use strict" is a no-op. If you add "use strict" and don't test it in a strict environment, you could be leaving a

JavaScript Closures - Using the ECMA Spec, please explain how the closure is created and maintained

瘦欲@ 提交于 2019-11-30 04:30:33
I'm reading about JavaScript closures . I'm familiar with Execution Contexts , how the Lexical Environment is maintained, and very familiar with Lexical Scoping . I want to know how closures in JavaScript are created and maintained . Sometimes it's hard for me to grasp such important concepts without knowing how it is actually doing it. I know that, according to Wikipedia, a closure is is a function or reference to a function together with a referencing environment—a table storing a reference to each of the non-local variables (also called free variables) of that function. But my question is,

Polyfill or workarounds for ECMAScript5 new features?

北慕城南 提交于 2019-11-30 03:02:55
问题 I want to write my JS code with the new ECMAScript5 features that working today and in the future. As not all browsers support all the features (especially IE) such as Object.create , Array.isArray or JSON . I knew a few workarounds such as use json2.js to archieve JSON support. I want to know more polyfills or workarounds for the other feature. 回答1: Take a look at these : https://github.com/kriskowal/es5-shim https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-Browser-Polyfills ( es5

Motive behind strict mode syntax error when deleting an unqualified identifier?

試著忘記壹切 提交于 2019-11-30 01:16:18
I'm having trouble understanding why, in strict mode, a syntax error occurs when delete is used on an unqualified identifier. In most cases, it makes sense... if you are declaring variables in the usual way with the var keyword, and then trying to use delete on them, in non-strict mode it would silently fail, so it makes sense for strict mode to fail with an error in those cases. However, there are cases where you can't delete identifiers that are qualified: (function() { // "use strict"; var obj = Object.create({}, { bloop: { configurable: false } }); delete obj.bloop; // throws TypeError in

How to force google closure compiler to keep “use strict”; in the compiled js code?

孤街醉人 提交于 2019-11-29 23:54:08
If you're using the module pattern and have something like this: (function () { "use strict"; // this function is strict... }()); and compile the code using the Google Closure Compiler, the "use strict"; directive will not make it into the compiled file. So how do you prevent the Closure Compiler from removing the ES5/strict directive? (Note that I don't want to use the other mode of enforcing ES5/strict mode, which is to simply add the "use strict"; to the first line of the compiled file. I want to use the module pattern as described here .) This isn't the greatest answer, but as far as I can

EcmaScript 5 browser implementation

我的未来我决定 提交于 2019-11-29 22:53:07
So Safari and Chrome have started in their betas to implement some ES5 stuff. For instance Object.create is in them. Do any of you know if there is a website that shows the progress made in the browsers? ATM i need to use Object.freeze, and wanted to see which browsers (if any) supported that yet. Tihauan Here's an up to date list for major engines: http://kangax.github.com/es5-compat-table/ 来源: https://stackoverflow.com/questions/2280115/ecmascript-5-browser-implementation