ecma262

Is there an i18n (Intl) shim for JavaScript?

十年热恋 提交于 2019-12-03 01:42:31
I am looking for a shim for the ECMAScript Internationalization API . Does anyone know of such a project? (Even if it's still currently a work-in-progress.) Andy E Yes, there's a polyfill for ECMA-402 (aka ECMA Internationalization API Specification) available at https://github.com/andyearnshaw/Intl.js . For use in Node.js applications, you can install with NPM: npm install intl It's also available as a Bower component for the front-end: bower install intl There's support for NumberFormat and DateTimeFormat , but no support for Collator . Currently, for client-side browser environments, you

argumental reference inconsistency in javascript

匆匆过客 提交于 2019-12-02 09:35:47
I have recently encountered a nasty issue in JS. Let say we pass a map, an array of objects to a function f. var o=[{a:0}]; function f(a){ for(var i in a){ if (a.hasOwnProperty(i)){ a[i]=null; } } return a; }; var outp=f(o); alert(outp[0]+" === "+o[0]+" : "+(outp[0]===o[0])); // here we expect loose equality, and equality in type, //furthermore it should identically equal as well, and we got right! But, we can not pass total responsibility of an object to a function as argument, same like in functional paradigm o=(function(o){return o})() , because any kind of modification to o is not

Why is the dollar sign no longer “intended for use only in mechanically generated code?”

扶醉桌前 提交于 2019-12-02 02:14:33
In ECMA-262, 3rd edition [PDF] , under section 7.6 ("Identifiers," page 26), we see the following note: The dollar sign is intended for use only in mechanically generated code. That seems reasonable. Many languages commonly used for generating or embedding JavaScript hold a special meaning for $ , and using it in JavaScript identifiers within those languages leads to unexpected behavior . The "mechanically generated clause" appeared in edition 2. In edition 1, it was not present. As of edition 5, it disappears again without explanation, and it remains absent from the working draft of the 6th

Why is the dollar sign no longer “intended for use only in mechanically generated code?”

倾然丶 夕夏残阳落幕 提交于 2019-12-02 01:59:15
问题 In ECMA-262, 3rd edition[PDF], under section 7.6 ("Identifiers," page 26), we see the following note: The dollar sign is intended for use only in mechanically generated code. That seems reasonable. Many languages commonly used for generating or embedding JavaScript hold a special meaning for $ , and using it in JavaScript identifiers within those languages leads to unexpected behavior. The "mechanically generated clause" appeared in edition 2. In edition 1, it was not present. As of edition 5

What's the difference between VarDeclaredNames and VarScopedDeclarations?

我与影子孤独终老i 提交于 2019-12-01 14:48:45
I'm reading EcmaScript specification. At 9.2.12, there are: 11.Let varNames be the VarDeclaredNames of code. 12.Let varDeclarations be the VarScopedDeclarations of code. And at 13.1.5 and 13.1.6: 13.1.5 Static Semantics: VarDeclaredNames Statement : EmptyStatement ExpressionStatement ContinueStatement BreakStatement ReturnStatement ThrowStatement DebuggerStatement Return a new empty List. 13.1.6 Static Semantics: VarScopedDeclarations Statement : EmptyStatement ExpressionStatement ContinueStatement BreakStatement ReturnStatement ThrowStatement DebuggerStatement Return a new empty List. They

What's the difference between VarDeclaredNames and VarScopedDeclarations?

此生再无相见时 提交于 2019-12-01 13:36:03
问题 I'm reading EcmaScript specification. At 9.2.12, there are: 11.Let varNames be the VarDeclaredNames of code. 12.Let varDeclarations be the VarScopedDeclarations of code. And at 13.1.5 and 13.1.6: 13.1.5 Static Semantics: VarDeclaredNames Statement : EmptyStatement ExpressionStatement ContinueStatement BreakStatement ReturnStatement ThrowStatement DebuggerStatement Return a new empty List. 13.1.6 Static Semantics: VarScopedDeclarations Statement : EmptyStatement ExpressionStatement

When did all browsers start supporting the String.replace(regexp, replacement_function)?

允我心安 提交于 2019-11-30 17:41:52
According to the 6th Edition of JavaScript: The Definitive Guide (Flanagan, 2011): ECMAScript v3 specifies that the replacement argument to replace() may be a function instead of a string. I'm looking at some code written in 2005, where a complicated workaround has been used to replace parts of a string. The comments for the code clearly indicate that it originally used the functional replace() method but that the workaround was necessary for cross-browser compatibility. ECMAScript v3 came out in 1999 and, as far as I can tell (from this discussion post and this blog post ), ECMAScript v3 was

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

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

Why does `typeof this` return “object”?

大城市里の小女人 提交于 2019-11-30 05:58:02
问题 var f = function(o){ return this+":"+o+"::"+(typeof this)+":"+(typeof o) }; f.call( "2", "2" ); // "2:2::object:string" var f = function(o){ return this+":"+(typeof this)+":"+(typeof o); }; var x = [1,/foo/,"bar",function(){},true,[],{}]; for (var i=0;i<x.length;++i) console.log(f.call(x[i],x[i])); // "1:object:number" // "/foo/:object:object" // "bar:object:string" // "function () {\n}:function:function" // "true:object:boolean" // ":object:object" // "[object Object]:object:object" I see