CSS “contain” property

The contain CSS property allows you to define an element as a style boundary in order to optimize the browser’s paints, layouts, composite, and style contexts calculations.

.el {
    contain: strict;
}

Read more

#id is in window

DOM node IDs are directly available in the window object.

<div id='foo'></div>
console.log(window.foo) // HTMLElement

Though, you shouldn’t access the DOM that way.

Read more

Synthetic events

We can create our own event types, listen to and emmit them from anywhere, and implement event driven behaviors.

$el.addEventListener('foo', () => { 
    console.log('received foo event') 
})
$el.dispatchEvent(new CustomEvent('foo'))
// 'received foo event'

Read more

Getters & setters

JavaScript allows you to intercept when an object property is accessed or assigned to.

const foo = {
    bar: 42,
    get bar() { return this.bar + 1 }
}
console.log(foo.bar) // 43

Read more

Thenables & trigger promises

Any object containing a then() property — also called a thenable — can be turned into a promise.

const foo = {
    then: fn => fn(42)
}
Promise.resolve(foo).then(console.log) // 42

Read more