I was curious about testing JavaScript performance and did some research on it.
When I talk about JavaScript performance here, I'm not talking about things like time-to-first-byte, time-to-interaction, etc.. I'm talking about raw computing speed – how long does function X run compared to function Y.
I discovered we can use two methods to test performance – performance.now and Date.now. I was curious about the difference between them, so I made some experiments to document my findings.
I often get requests from people who want me to look through their work and provide them with feedback. While asking for feedback is a praise-worthy thing – because you want to improve – I don't have the time and resources to give feedback to everyone.
I suspect that's the case for others too. We're all busy.
When I ask others for feedback, sometimes I don't get responses. Sometimes I get subpar responses. I found it hard to get specific, detailed, and actionable advice from people unless they have a skin in the game for helping me out.
For example: You're paying for their services, so they have an incentive to help you. Another example: You're in a project together with them; if you succeed they succeed.
If you get specific and helpful feedback, great! Use that feedback and improve. But the question remains: How can you improve if you don't get feedback?
I saw an [article][1] by [Sarah Drasner][2] about how she created [Netlify's million-developers][3] site on CSS Tricks. I was intrigued by how the site was created. (Not the Vue parts, but she coded up the paths on the site).
What paths?
Here's the Mobile and Desktop view, side by side. I'm talking about the winding paths that lead from one set of content to another set of content.
<Image
src="/assets/2020/million-devs/million.png"
alt="Million Devs site: mobile and desktop versions compared. "
/>
I always wanted to create a site with curved elements, similar to this. So I took the chance to inspect the code. What I realised blew my mind 🤯.
I was living a comfortable life back in 2014. I was living my dreams. I freelanced and I earned an equal amount to my friends who held full-time jobs. I was free.
Or so I thought.
The first three years of freelancing were exciting. I simply loved hopping around different agencies, creating websites for a living, making friends, and knowing more people. I felt I could do this forever. But I was wrong.
Getter and Setter functions are collectively known as accessor functions. In my previous two articles, I talked about how I created [mix][1] because I wanted to use Getter and Setter functions.
But why do we even use Getters and Setters in the first place?
<Image
src="/assets/2020/accessors/why-use-accessors.png"
alt="Why use getters and setters?"
/>
Object.assign is the standard way to copy properties from one object to another. It is often used for copying properties that are one-layer deep. (One-layer deep means there are no nested objects).
It can be used to extend settings from a default object. Here's an example:
Unfortunately, Object.assign doesn't copy accessors. (Accessor is a term for Getter and Setter functions). Object.assign reads the value of a Getter function and copies that value instead.
let count = 0
const one = {}
const two = {
get count() {
return count
},
set count(value) {
count = value
},
}
const three = Object.assign({}, one, two)
console.log('two:', two)
console.log('three:', three)
Try logging two and three in a Node environment. Accessors will be logged clearly. You'll immediately see that three.count is NOT an accessor.
<Image
src='/assets/2020/copy-accessors/accessors-not-copied.png'
alt='Accessors are not copied into three.'
/>
To position the popover perfectly, I need to know the horizontal and vertical centers of the button that triggers the popover. Here's one example of a calculation I had to make.
<Image
src="/assets/2020/bounding-box-helper/popover-calc.jpg"
alt="One of the popover calculations."
/>
For the longest time, I thought that "Polymorphing" was about converting something into sheep (thanks to Warcraft). The sheep image stuck with me and made it hard to understand exactly what Polymorphism is.
Today I want to explore what Polymorphism actually is. (Fun fact: Most articles about Polymorphism in JavaScript covers less than 1/3 of what it actually is).
There are many flavours to arrays in JavaScript. The possible methods you to create or change arrays are: unshift, shift, push, pop, splice, concat, slice, destructuring, rest operators, and spread operators.
There are also looping methods like for, forEach, map, filter, reduce, find, findIndex.
17 different flavours! 😱.
I want to document how I choose the array methods I use. This should help you understand how to pick methods.
I was tinkering around with Dynamic Imports this week when I saw Snowpack in the [JavaScript Weekly][1] newsletter. It caught my eye and I gave it a whirl.
I managed to get a decent Eleventy + Snowpack + Sass setup in a couple of hours. I'll share this setup next week. But first, I want to share some things I noticed about Snowpack.
I talked about the key bindings I used to switch between tabs and panels last week. This week, I want to share some wicked shortcuts I use for the Integrated Terminal.
"I don't get JavaScript. I can't make components from scratch. My mind goes blank when I stare at a blank JavaScript file. I guess I can't do it because I don't know how to think like a programmer".
Sounds familiar? You're not alone, my friend. Many people faced the same problem when they try to write JavaScript.
No more.
Let today be the day where you learn to think like a programmer.