Questions tagged [ecma]

ECMA is a standards organisation

214 questions
184
votes
4 answers

How to wait for a JavaScript Promise to resolve before resuming function?

I'm doing some unit testing. The test framework loads a page into an iFrame and then runs assertions against that page. Before each test begins, I create a Promise which sets the iFrame's onload event to call resolve(), sets the iFrame's src, and…
dx_over_dt
  • 13,240
  • 17
  • 54
  • 102
134
votes
3 answers

Why is String.prototype.substr() deprecated?

It is mentioned on the ECMAScript standard here that : ... These features are not considered part of the core ECMAScript language. Programmers should not use or assume the existence of these features and behaviours when writing new ECMAScript code.…
ElJackiste
  • 4,011
  • 5
  • 23
  • 36
47
votes
2 answers

Why is `(foo) = "bar"` legal in JavaScript?

In Node.js's REPL (tested in SpiderMonkey as well) the sequence var foo = null; (foo) = "bar"; is valid, with foo subsequently equal to "bar" as opposed to null. This seems counterintuitive because one would think the parenthesis would at least…
TERMtm
  • 1,903
  • 3
  • 23
  • 29
39
votes
2 answers

Which Edition of ECMA-262 Does Google Apps Script Support?

According to this thread from the old Google Group, Apps Script is based on ECMA-262 3rd Edition. This would seem to be supported by the fact that auto-completion in the editor displays 3rd Edition array functions. However the following code runs…
chrisbateskeegan
  • 1,013
  • 1
  • 11
  • 14
35
votes
4 answers

When to NOT use "strict mode" in javascript?

I've found this post-What does "use strict" do in JavaScript, and what is the reasoning behind it? And what I'm understanding here is that I should use strict always. But I wonder, if it was true, that always is better to use "strict mode", then It…
Ramon Marques
  • 3,046
  • 2
  • 23
  • 34
29
votes
7 answers

Why does Array.prototype.push return the new length instead of something more useful?

Ever since its introduction in ECMA-262, 3rd Edition, the Array.prototype.push method's return value is a Number: 15.4.4.7 Array.prototype.push ( [ item1 [ , item2 [ , … ] ] ] ) The arguments are appended to the end of the array, in the order in…
Bryce
  • 6,440
  • 8
  • 40
  • 64
17
votes
2 answers

NFC standards (NFC Forum, ISO/IEC, ECMA

I am often being asked about standards, the NFC is based on. I summarized my knowledge in the text below. I hope it can be an answer to such questions. Please feel free to correct it by posting comments and replies - I will include it into my…
STeN
  • 6,262
  • 22
  • 80
  • 125
15
votes
2 answers

Webpack generates arrow function in ES5

I want to use TypeScript modules and bundle them via Webpack. Here are my config files: webpack.config.js: const path = require('path'); module.exports = () => { return { entry: './index.ts', output: { filename:…
Ivan Adanenko
  • 445
  • 2
  • 6
  • 18
11
votes
3 answers

Delete a dynamic key from a TypeScript object

In TypeScript it is quite simple to clone an object: const a = {...b} or clone and update const a = {...b, c: 'd'} So for example, I have this code: const a = { 'something': 1, 'e': 2, }; const c = 'something'; delete a[c]; Is there a nice…
Nguyen Phong Thien
  • 3,237
  • 1
  • 15
  • 36
10
votes
1 answer

How do I get Istanbul to recognize code coverage when using ESM?

I'm using ESM to loading my modules and I use them in this way: // More info on why this is needed see (https://github.com/mochajs/mocha/issues/3006) async function wire(){ await import("./Sanity.spec.mjs"); await…
JGleason
  • 3,067
  • 6
  • 20
  • 54
10
votes
4 answers

How to get a leading '+' for positive numbers in Intl.NumberFormat?

I'm using Intl.NumberFormat to convert a number type to a formatted string in typescript/javascript in Angular2. I want a native solution and this is ideal, but I need a leading plus sign to be included for positive numbers. If this is not possible…
CodeCabbie
  • 3,098
  • 2
  • 19
  • 30
8
votes
1 answer

How do I find the latest Typescript target support for any version of node?

Assuming any version of Node, how do I find the corresponding Typescript Compiler Option for target that gives most the functionality? I want to remove the guest work. Specify ECMAScript target version: "ES3" (default), "ES5", "ES6"/"ES2015",…
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468
7
votes
1 answer

Why does Promise.all() tigger Array.prototype.then if defined?

Having the following pice of code... const array = [ Promise.resolve(1), Promise.resolve(2), Promise.resolve(3) ]; Array.prototype.then = function () { console.log('Why does this gets triggered?'); } Promise.all(array) .then(result =>…
Iván E. Sánchez
  • 1,183
  • 15
  • 28
7
votes
1 answer

How to make configurable npm package

We have many projects and we want to share our component between them but the problem is each project have their special config file that indicates the server URLs or custom error handler module and etc. My question is, how to publish a package in…
javad bat
  • 4,236
  • 6
  • 26
  • 44
7
votes
1 answer

Why does JSON encode UTF-16 surrogate pairs instead of Unicode code points directly?

To escape a code point that is not in the Basic Multilingual Plane, the character is represented as a twelve-character sequence, encoding the UTF-16 surrogate pair. So for example, a string containing only the G clef character (U+1D11E) may be…
TRiG
  • 10,148
  • 7
  • 57
  • 107
1
2 3
14 15