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.
When I got my Windows computer, the first thing I did was to set up Windows so it [mirrors the writing system I had on Mac][1]. I also [mirrored Mac's modifiers as much as possible][2].
Then, I set up my [Windows development environment][3] (with Windows Subsystem for Linux) on my new Windows computer.
Next, I had to do was to make Visual Studio Code on both Mac and Windows play nice.
Mac changes the brightness of your screen automatically. It brightens up when you're in a bright place. It dims when you're in a dark place. They do it elegantly and slowly. Most of the time, their brightness adjustment is great.
The same cannot be said for Windows. I noticed huge changes in the screen's brightness (which causes me to get distracted). I hated it, so I removed it.
Turns out, it's not as easy as you think it should be.
I did a post-mortem for Build Your Developer Brand (which I gave last Friday). I wanted to share this review openly in case anyone is interested in my thoughts.
I finally understood how to work with Node, Express, and MongoDB. I want to write a comprehensive tutorial so you won't have to go through the same headache I went through.
After a [horrible experience][1] with my 2018 Macbook, I decided it was time to buy a Windows device as my backup machine. I chose to use Windows as a backup because:
Mac is expensive!
My old Mac is a goner
I need a Windows computer for accessibility testing (NVDA + Firefox combination anyone?)
I ended up buying a Surface Laptop 3.
Setting up Windows was harder than I imagined. It was especially hard because I wanted this Windows machine to mirror everything I do on Mac.
In this series of articles, I'll explain everything I did to configure my new Windows machine. This should help you out if you're switching from Mac to Windows.