[[Class]] property in JavaScript objects
The [[Class]] property of object is set according to how an object is created IIUC. Is this why some objects are rendered to the Chrome console in a meaningful way e.g. MyFoo and others are simply...
View ArticleChaining promises returned from a generator function
I want to chain the promises returned by a generator function.I am expecting this to print:started...result is: initial valueresult is: waited for 10msresult is: waited for 20msdoneBut it...
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 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 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 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 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 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 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 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 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 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 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 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 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 ArticleIs scope.$apply synchronous in AngularJS?
Is the following code synchronous in AngularJS?scope.$apply(function(){ console.log('foo');});
View Article