Questions tagged [ecmascript-next]

For questions about upcoming ECMAScript features that are not scheduled to be part of a specific version yet (anything that is a stage 3 or lower proposal).

Filter by
Sorted by
Tagged with
1 vote
1 answer
617 views

Valid with the RegExp u flag, but not with the v flag

I am getting the below console warning for this regex pattern: ^[a-zA-Z0-9+_.-]+@[a-zA-Z0-9]+\\.[a-zA-Z0-9]+$ Pattern attribute value ^[a-zA-Z0-9+_.-]+@[a-zA-Z0-9]+\.[a-zA-Z0-9]+$ is valid with the ...
DuckSoup's user avatar
1 vote
2 answers
96 views

Typescript exclude methods from class once invoked

I have a use case where I want to exclude methods from return type of class method once they are invoked. ie, let us assume I have a class Setup having method step1, step2 and step3. class Setup { ...
Anirudh Modi's user avatar
  • 1,799
3 votes
1 answer
741 views

Need explanation of error message 'TypeError: Receiver must be an instance of class' [duplicate]

When I run this code: 'use strict'; class Base { constructor() { this._public(); } } class Child extends Base { constructor() { super(); } _public() { this.#privateMethod(); ...
Dmitry Koroliov's user avatar
0 votes
1 answer
235 views

sam build outpus cjs file instead of mjs file

When I wanna build my lambda project by using sam cli, it gives me error like below. I use typescript and ES2022 and wait that it should outputs mjs files. But it outputs cjs files. So, cjs files don'...
hkaraoglu's user avatar
  • 1,335
3 votes
3 answers
132 views

How to convert Generator method to an Iterator

I have this recursive generator method which yields the values of a BST in ascending order: *inOrder(node){ if (node === null) { return; } if(node.left){ yield * this....
Alexander Mills's user avatar
0 votes
1 answer
78 views

Copy properties but not function properties, using spread operator or similar

Is there a way in JS to copy all non-function properties using the spread operator or the like? this won't do it obviously (since it will copy function references): getSerializableData(): Partial<...
Alexander Mills's user avatar
0 votes
1 answer
161 views

Can async / await always be automatically replaced by Promises chains?

Usually, Promises chains can be rewritten using async/await const f = () => Promise.resolve(1).then(a => a+1) can be translated to const f = async () => { const a = await ...
Fabiano Taioli's user avatar
3 votes
1 answer
38 views

Does ECMAScript Regular Expressions match its syntax characters?

I'm referring to ECMAScript regular expression syntax defined in https://tc39.es/ecma262/#sec-regexp-regular-expression-objects. I checked how the following pattern matches in a regular expression via ...
BunnyJamless's user avatar
0 votes
0 answers
29 views

Addressing Privacy Concerns Regarding Push Notifications

To facilitate push notifications, is it absolutely necessary for a browser to host servers to accomplish this? Each time I launch Firefox, prior to going to any websites, Firefox makes a connection to ...
Lonnie Best's user avatar
  • 9,671
2 votes
0 answers
74 views

How to check is incumbent settings object tracking working in the browser

There is interesting section in the mdn article of Promises and that's it incumbent settings object tracking. But the most interesting at the end, there is written: In the above example, the inner ...
MaximPro's user avatar
  • 553
1 vote
1 answer
718 views

this is changed to undefined with webpack + typescript + module = "esnext"

I have a setup with webpack + typescript (using ts-loader). To enable code splitting with webpack, you must set module to esnext in tsconfig: // tsconfig.json { "compilerOptions": { &...
Flion's user avatar
  • 10.4k
0 votes
0 answers
20 views

JS function params destructuring, still assign whole parameter [duplicate]

Say I have this function: const myFn = obj => doSomethingWithKey(obj.key); I can use destructuring, which is much more elegant: const myFnV2 = ({key}) => doSomethingWithKey(key); But can I ...
Augustin Riedinger's user avatar
0 votes
1 answer
222 views

Tuples/ Records in JavaScript

I was referring to this link: Future Javascript: Records and Tuples and I was wondering, what is the reasoning behind these? We can still use Object.freeze with both arrays and objects to achieve this....
Rajesh's user avatar
  • 24.3k
0 votes
1 answer
68 views

How to import prototype getter from custom library using Object.defineProperty()

I want to create a reusable library for my projects. For this exercise, I've got one main library, and then an extension library for "identity" related functionality. The idea is that I can ...
CoderBang's user avatar
  • 123
0 votes
1 answer
52 views

`part:` modifier in node import statement

I came across this code in a javascript / Node project but can't find any explanation online as to what it is and how it works. import PatchEvent, {set, unset} from 'part:@sanity/form-builder/patch-...
Michael Martinez's user avatar
0 votes
1 answer
42 views

Early Error in annex semantics of GlobalDeclarationInstantiation

I couldn't find any sources speaking about the next point in specification (let it be GlobalDeclarationInstantiation): ii. If replacing the FunctionDeclaration f with a VariableStatement that has F ...
MaximPro's user avatar
  • 553
0 votes
1 answer
45 views

Replacement steps in operation BlockDeclarationInstantiation

Recently, I've noticed that operation BlockDeclarationInstantiation has some changes. Take a look at these points: Perform ! env.CreateMutableBinding(dn, false). NOTE: This step is replaced in ...
MaximPro's user avatar
  • 553
0 votes
0 answers
27 views

Array.prototype.at and the postfix/prefix increment/decrement operator [duplicate]

const nums = [1, 2, 3]; this works just fine: ++nums[2] // 4 but this does not: ++nums.at(-1) // ReferenceError: Invalid left-hand side expression in prefix operation Can someone please explain to ...
Calogero Mandracchia's user avatar
1 vote
1 answer
486 views

Extra execution context in async functions

When I was reading spec I saw next part: NOTE: Copying the execution state is required for AsyncBlockStart to resume its execution. It is ill-defined to resume a currently executing context. I don't ...
MaximPro's user avatar
  • 553
0 votes
1 answer
768 views

module.exports give undefined while print module indicates it's not undefined?

I'm trying to work with a CommonJs module which exports a variable conditionally based on whether module and module.exports are undefined. The issue I'm currently having is that sometimes when I use ...
Psidom's user avatar
  • 208k
3 votes
0 answers
749 views

How do I exclude *.spec.mjs using c8?

I have the following... App.mjs import express from "express"; const port = process.env.PORT || 4000; class CommunicationsApplication{ constructor() { this.app = ...
Jackie's user avatar
  • 21.8k
1 vote
3 answers
974 views

Why is my NYC Code coverage not working with ESM?

I have the following code... App.mjs import express from "express"; const port = process.env.PORT || 4000; class CommunicationsApplication{ constructor() { this.app = ...
Jackie's user avatar
  • 21.8k
4 votes
2 answers
651 views

How to use stage 3 features in TypeScript?

Array.prototype.at() is currently a stage 3 proposal, I've tried setting "lib": ["ESNext"] in my tsconfig.json, but I still got: Property 'at' does not exist on type 'number[]'. ...
Wenfang Du's user avatar
  • 8,177
1 vote
1 answer
47 views

What is the ECMAScript feature that allows developers to put spacing between numbers?

I vaguely remember newer versions of JS/ECMAScript allow users to put spaces within numbers for readability. E.g. something like: const age = 1 000 000; However my linter complains, probably because ...
mikemaccana's user avatar
1 vote
1 answer
2k views

How to override object destructuring for ES class just like array destructuring

TL;DR How do I make {...myCls} return {...myCls.instanceVar}? Actual Question I'm trying to implement a custom version of *[Symbol.iterator]() { yield this.internalObj; } such that object-spreads of ...
yuyu5's user avatar
  • 336
-1 votes
1 answer
217 views

JS/ES offline and store a Promise for later use

How can I offline this 'example' promise--- i.e. attributing the promise to a variable for later passing/use--- // this example promise works OK... // just test with x=0 and x<>0 var x=0; ( ...
ZEE's user avatar
  • 2,817
2 votes
2 answers
1k views

Javascript: default value on missing property

Consider the following: var obj = { something: "blabla", otherthing: "mehmeh" } let a = obj["something"]; // blabla let a = obj["doesnotexist"]; // ...
resle's user avatar
  • 2,216
0 votes
1 answer
49 views

How can a JavaScript program know if a global property name was defined by ECMA-262?

Consider a hypothetical function called isEcmaGlobal that returns true for string names of ECMA-262 globals. $ node > isEcmaGlobal('Array') true > isEcmaGlobal('process') false How would one ...
Sage Gerard's user avatar
  • 1,301
0 votes
1 answer
68 views

How I can set general getter for an existing object?

I'm interested in adding common getter which would executes on every property get call of an existing object. All we know how to set getter for specific property, but can we set getter which's ...
dmitryprogrammer's user avatar
1 vote
1 answer
564 views

Stackblitz.com: error importing a module within another module

Stackblitz.com is an excellent resource for creating small experimental projects. However, today I ran into a problem. I created a stackblitz plain ecmascript project with the following folder ...
KooiInc's user avatar
  • 118k
2 votes
8 answers
144 views

What's the shortest way to copy only selected attributes in JavaScript?

Given the following two objects: let a = { foo: 'bar' }; let b = { one: 1, two: 2, three: 3, four: 4, five: 5, six: 6, seven: 7 }; We can assume that all values within these objects ...
Timo Ernst's user avatar
  • 15.1k
3 votes
1 answer
628 views

Import/Export name collision resolution

Testing in Node JS the following modules layout, looks like local exported definitions always replace external exported in case of name collision (see f1 in B.js). A.js export const f1 = 'A' B.js ...
Fabiano Taioli's user avatar
-2 votes
1 answer
59 views

Who is responsible for adding new JavaScript features?

Which organization is appointed for implementing new JS features? For example, adding a new reverse string capability, or anything else that would be introduced in ESNext?
April Henig's user avatar
0 votes
0 answers
108 views

JavaScript Spec - Relevant vs Surrounding Agent

Reading through the JavaScript and related specifications, these two concepts appear: Relevant agent (HTML) Surrounding agent (ES) Some of the spec uses both. For example, in the steps of 4.2.2.5 ...
tsconstraints's user avatar
1 vote
2 answers
120 views

Is the intrinsic object creation order mentioned by the ECMAScript Specification defined somewhere?

This is a question regarding the latest revision of ECMA-262. At https://tc39.es/ecma262/#sec-createintrinsics it says The creation of the intrinsics and their properties must be ordered to avoid any ...
Ojad Yref's user avatar
0 votes
0 answers
25 views

Best way to check if JS variable is / isn't more than one value? [duplicate]

I often write this repetitive code: if (SERVER_ENV == "TEST" || SERVER_ENV == "PROD" || SERVER_ENV == "QA") { // ... } Is there a better way to write conditional ...
cbdeveloper's user avatar
  • 27.1k
1 vote
1 answer
117 views

Nullish Coalescing Postfix Operator?

I want to increment a property value, but initialize it to 0 if it doesn't exist. This works, but is a little clunky: x = { }; let i = 0; x[i] = (x[i]||0) + 1; // Increment by one. (If not present, ...
Garrett's user avatar
  • 2,926
0 votes
1 answer
160 views

How to initialize private property of a class for a test

I'm trying to write a test using JEST to a class I wrote with static properties that resembles the following: class DataManager { static #data = null; static getData = () => { ...
Ohad Yeahhh's user avatar
1 vote
1 answer
109 views

What is the standard way to create an Angular Component in the browser?

I am trying to create a simple JS/ESM based Angular example. It has been a while since I have been in the angular space and I see there are really 2 options Using the UMD lib (I would like to avoid ...
Jackie's user avatar
  • 21.8k
3 votes
1 answer
646 views

Deno: VS Code typescript doesnt know ES6 [duplicate]

I am building an app with deno and typescript. As my IDE I'm using VS Code. When I'm trying to use modern javascript syntax like await and flatMap VS Code underlines these statements in red and shows ...
IceRevenge's user avatar
  • 1,411
0 votes
2 answers
507 views

JS Object destructuring/restructuring is unsafe if values are undefined and "in" operator is used on the new object. How to get around this?

Consider the following code. I know it's a bit contrived, but it's a simplification of a more complex problem that I ran into while writing a custom react hook for debouncing using lodash: import { ...
KFunk's user avatar
  • 2,876
1 vote
2 answers
1k views

How does the JavaScript optional chaining(?.) operator works?

I was looking into the new JS optional chaining?. operator. It helps us from getting errors like this, TypeError: Cannot read property ‘x’ of undefined You can write const obj = {a: 1}; console.log(...
Md Sabbir Alam's user avatar
22 votes
1 answer
9k views

Mapping of Node.js version to ECMAScript version [closed]

Is there a mapping somewhere from Node.js version, e.g. 0.10, or 14, to the corresponding ECMAScript version, e.g. ES5, ES2020? As this question is closed, I can't post the solution I came up with as ...
balupton's user avatar
  • 46.6k
2 votes
1 answer
88 views

Is there any way to reflect public instance class fields from the javascript class declaration?

The ecmascript candidate spec allows to declare class fields like: class A { foo; } or with value assignment like: class A { foo = 'abc'; } Public instance fields spec on MDN Is there any ...
majo's user avatar
  • 381
8 votes
1 answer
374 views

Why are arrow functions as static members values not lexically scoped?

class Foo { static v = 123; static bar = () => this.v; } console.log(Foo.bar()); I expect this code to return undefined, because arrow functions are lexically scoped, hence this must be ...
zerkms's user avatar
  • 248k
1 vote
1 answer
510 views

Typescript won't emit import statements as-is

My index.html imports only one script with <script type="module" src="./index.js"></script> And at the top of index.ts are the now-standard import statements import { ...
Ron Newcomb's user avatar
  • 2,856
1 vote
0 answers
113 views

How do I import @material/mwc-button without precompiling?

I have the following code... <html> <head></head> <body> <mwc-button label="Hello World"></mwc-button> <script src="https://unpkg.com/...
Jackie's user avatar
  • 21.8k
2 votes
1 answer
241 views

Detect TD element by inner value and move it to be last

Trying to better my skills with ECMAScript with moving elements and their content. Regarding my scenario, Once the DOM is ready, I want to... Check to see within my fourth <tr>, if there is a &...
klewis's user avatar
  • 7,337
0 votes
0 answers
142 views

why is the `throw` Iterator Interface method never called in the for-of loop?

according to ECMAScript specification an object implementing the Iterator Interface must have the next method, but there are also optional return and throw methods (see the specs here: https://tc39.es/...
roomcayz's user avatar
  • 2,279
0 votes
1 answer
935 views

Syntactic sugar for JavaScript Constructor [duplicate]

Let's say we have a simple constructor; function Person(firstName, lastName) { this.firstName = firstName; this.lastName = lastName; } I'd rather use as follows. function Person(firstName, ...
gurkan's user avatar
  • 862

1
2 3 4 5
9