Why both capture and bubble events in Javascript dom?

Historical accident The answer seems to be historical accident, not intentional design. Back in the old days, Netscape advocated event capturing, while Microsoft promoted event bubbling. Both are part of the W3C Document Object Model Events standard (2000). – Arun P Johny If this is correct, the events of the browser wars in the 1990s are still shaping Javavscript into the 2020s! In a way, this is unsurprising: backwards compatibility is important, which means features are often in a way that seem inelegant in hindsight....

March 30, 2024

Anonymous functions have no reference in memory

I ran into a small bug today. Following a tutorial, I added an anonymous function as the second argument to my window.addEventListener, i.e. window.addEventListener("popstate", () => console.log("hello world")) I then struggled to remove it with window.removeEventListener("popstate", () => console.log("hello world")) At first I tried to solve it with studying in detail the documentation for window.removeEventListener. But soon I changed track: how can I find out what Event Listeners there are in my DOM (or in my window object)?...

March 25, 2024

In Array.sort()’s compareFn, the order of a and b doesn't matter

MDN documentation on Array.prototype.sort() says of the the optional CompareFn, A function that determines the order of the elements. The function is called with the following arguments: a The first element for comparison. Will never be undefined. b The second element for comparison. Will never be undefined. It should return a number where: A negative value indicates that a should come before b. A positive value indicates that a should come after b....

March 24, 2024

Can someone tinker her way into programming in the 2020s?

My answer is no. The attention economy has closed off a route that was available as recently as a decade ago. Background: I came across an unusually patient and helpful answer by adsy on StackOverflow, which led me to this article. After reading it, it struck me that the way people first experience computers and programming has transformed in the last 20 years. adsy got into programming the early 2000s. The dot-com bubble had burst....

March 23, 2024

Installing Jekyll on a Mac in March 2024

Why I wanted to run Jekyll on my Mac to see changes locally. Process Follow the quickstart guide on official Jekyll website Problem 1: gem install jekyll received no output. Solution: terminal helpfully warned that. You don’t have /Users/username/.gem/ruby/2.6.0/bin in your PATH, gem executables will not run. Problem 2: find the PATH Solution: (a) echo @$PATH``, (b) edit .bash_profile``` Problem 3: still no Jekyll Use the which command to find out why Jekyll isn’t recognised...

March 23, 2024

Promises always return promises

I was trying to make a Promise object return an ordinary value (e.g. a number or a string), but failed. And then I realised that Promises are never intended to return values other than Promises. Otherwise how can one “chain” then with .thens? I can do what I wanted to do with this instead. // declare a variable without initialising it let newValue // declare and initialise a promise const myPromise = new Promise((resolve, reject) => { resolve("foo"); }); // assign the value of the resolved promise to the variable myPromise....

March 22, 2024

Setting up the blog

This website was set up by following this helpful tutorial.

March 21, 2024