Why is BigInt not a constructor function, unlike Number, Boolean and String?
Number, Boolean and String are constructor functions that correspond to those primitive types.BigInt is a function that corresponds to the BigInt primitive type, but it is not a constructor...
View ArticleDoes assigning a string to another variable copy its memory?
Does the following result in a memory copy operation?1: var foo, bar;2: foo = 'abc';3: bar = foo;Is the memory representation of foo copied into the memory pointed at by bar on line 3?Does this change...
View ArticleAnswer by Ben Aston for Set multiple properties at the same time instead of...
Here's one way using Object.fromEntries:const o = Object.fromEntries(['w', 'a', 's', 'd'].map((v) => [v, true]))console.log(o)...or if the object already exists and you want to change a subset:const...
View ArticleAnswer by Ben Aston for 'const string' vs. 'static readonly string' in C#
Both static string and const string have different use cases (although both are treated as static).Use const only for truly constant values (e.g. speed of light - but even this varies depending on...
View ArticleHow can I spy on a getter property using jasmine?
How can I spy on a getter property using jasmine?var o = { get foo() {}, };spyOn(o, 'foo').and.returnValue('bar'); // Doesn't work.This also does not work...
View ArticleAvoiding an ambiguous match exception
I am invoking a static method Parse on a type via reflection because I do not know the type of the object at compile-time (I do know, however, it has a Parse method, taking a string).However, I am...
View ArticleIs scope.$apply synchronous in AngularJS?
Is the following code synchronous in AngularJS?scope.$apply(function(){ console.log('foo');});
View ArticleIs it possible to wrap a setInterval in an async generator function?
Without using the Streams API, is it possible to wrap a setInterval in an async generator function, to simulate a never-ending stream?I know how to do it using setTimeout to supply the delay.Using...
View ArticleEscape a space in a file path string [closed]
I receive a file path string via JSON.parse, but I need to escape the spaces in the string with backslashes.How should I do this idiomatically in Javascript?For example:var input = JSON.parse('{...
View ArticleIs it possible to make a callable object non-callable?
In JavaScript, functions are callable.Can I remove this attribute from a function, leaving only a normal object?var foo = function () {};foo.[[callable]] = false; // pseudocodefoo(); // "foo is not a...
View ArticleChrome timeline - how can I determine the cause of a "Recalculate Style" log...
Profiling a page with the built-in timeline recorder in Chrome, I see repeated "Recalculate Style" entries. They have no obvious information to link them to DOM element or event.How can I best...
View ArticleAnswer by Ben Aston for setTimeout in object method continues to run after...
In the following code, an outer div forms the boundaries of a playfield and all game elements inside the playfield are represented by divs.Game state consists of an array of game elements (in this...
View ArticleWhen should I use yield* vs yield in redux-saga?
I want to call another saga from a saga.The saga is of course a generator function, and is asynchronous.Should I ever user yield * or should I always use yield?function* mySaga({ payload: { id, name }...
View ArticleOn a webpage can I hijack the vertical scrolling action and make it horizontal?
On a webpage can I hijack the vertical scrolling action and make it horizontal?Please try and ignore the potential usability issues.
View ArticleWhat is reentrancy in JavaScript?
I would like to improve my understanding of the word reentrant.Is this function reentrant?function* foo() { yield 1; yield 2;}And this one?function foo() { return 1;}And this one?var x = 0;function...
View ArticleReentrancy in JavaScript
I would like to improve my understanding of the word reentrant.Is this function reentrant?function* foo() { yield 1; yield 2;}And this one?function foo() { return 1;}And this one?var x = 0;function...
View ArticleAnswer by Ben Aston for Insert a string at a specific index
Instantiate an array from the stringUse Array#spliceStringify again using Array#joinThe benefits of this approach are two-fold:SimpleUnicode code point compliantconst pair =...
View ArticleHow do I apply a skin tone to an emoji in JavaScript?
Given this emoji, how can I programmatically apply a skin tone in JavaScript?Grinning face is 0x1F600.Dark Skin Tone is 0x1F3FF.Do I simply concatenate the values together?The following code, based on...
View ArticleComment by Ben Aston on On a memory level, is there a difference between...
@MichaelVigato You'd have to look at engine source code IMO. Classes provide an alternative way to coordinate object instantiation, most of which is simply an encoding of specific steps that could be...
View ArticleWhy does this async generator cause the JavaScript runtime to hang?
The following JavaScript causes the runtime to hang on Chrome (v80.0.3987.116) and Firefox (v72.0.2) on OSX 10.15.2.Why?Note that I am marking the iterator function as async.const iterable = { async...
View Article