Ask Your Developer

Ask Your Developer is Twilio co-founder Jeff Lawson’s advice to Businesses looking to survive and prosper in the digital age. In short, Jeff argues that: (1) Businesses need to embrace technology (esp. web technology) to compete; (2) Rather than buying them ready-made (e.g. from a consultancy), businesses do better by buying “software parts” and assemble a custom solution. For example, Twilio excels at providing tools for integrating mobile phone text-messaging to software programmes; Cloudfare specialises in protection from DDOS attacks.

READ MORE

object.property v. object[property]

I recently came across a situation where I was fetching information from a RESTful API. After some intermediate steps, I ended up with an array of objects, all of which have the same set of attribtues (e.g. including an id). I wanted to have a way of printing a list of ids of the objects, e.g. let attribute = id array.map(object => <li> object.attribute </li>) But this didn’t work. It took me a while before I realised what I needed is instead:

READ MORE

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.

READ MORE

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)?

READ MORE

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.

READ MORE