See this jsPerf test.
The most performant way to store data related to a certain element is to use a Map
. Besides being the fastest, it also allows you to store arbitraty data. Using dataset
and data-*
attributes only allow for string values.
See this jsPerf test.
The most performant way to store data related to a certain element is to use a Map
. Besides being the fastest, it also allows you to store arbitraty data. Using dataset
and data-*
attributes only allow for string values.
class SampleApp() { | |
constructor () { | |
this.pageLoadingPromise = null; | |
} | |
waitForDomContentLoaded() { | |
if (!this.pageLoadingPromise) { | |
// this is the first time; prepare the promise | |
this.pageLoadingPromise = new Promise(resolve => { |
async function getJson(url) { | |
return JSON.parse(await getFile(url)); | |
} | |
async function getFile(url) { | |
return new Promise((resolve, reject) => { | |
const request = new XMLHttpRequest(); | |
request.addEventListener("load", function () { | |
try { | |
resolve(this.responseText); |
/** | |
* Asynchronously sleep for the specified amount of time. | |
* @param {Number} millis | |
* @return {Promise} | |
*/ | |
function sleep(millis) { | |
return new Promise(resolve => setTimeout(resolve, millis)); | |
} |
// will print numbers from 0 to 19 | |
for (const x of range(20)) { | |
console.info(x); | |
} | |
// will print | |
// 0 0 | |
// 1 0 | |
// 0 1 | |
// 1 1 |
Example .ssh/config
file:
# severals rules that depend on the wildcard rule at the bottom
Host foo.com
HostName foo.com
User foo
IdentityFile /path/to/id-1
function sleep(ms) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
} | |
/** | |
* Shows how a timer fails to execute when we block the main thread. See `setIntervalDoesNotWorkWithBlockingWait()` for | |
* a solution to this. | |
* @returns {void} | |
*/ |
class FileDropZone { | |
/** | |
* @param {HTMLElement|String} dropZoneElement | |
*/ | |
constructor (dropZoneElement) { | |
dropZoneElement = typeof dropZoneElement === "string" ? document.getElementById(dropZoneElement) : dropZoneElement; | |
dropZoneElement.addEventListener("drop", this.onDrop.bind(this)); | |
dropZoneElement.addEventListener("dragover", event => event.preventDefault()); |