A JavaScript class:
class Person {
constructor(firstName) { // (A)
this.firstName = firstName; // (B)
}
describe() { // (C)
import * as assert from 'assert/strict'; | |
/** | |
* I’m not sure if this is practically useful but: | |
* The single utility method .findValue() for Arrays can be used | |
* to implement several existing Array methods. | |
*/ | |
Array.prototype.findValue = function (cb, defaultResult, thisValue) { | |
thisValue ??= this; | |
for (let i=0; i<this.length; i++) { |
/* | |
Functionality – when executed, these lines are copied to the clipboard: | |
1. The URL of the current web page. | |
2. The title of the current web page (as originally written) | |
3. The title of the current web page (converted to sentence case with a crude algorithm) | |
4. Optionally: The currently selected text (if any). | |
Installation: Create a bookmark whose URL is the code below (including `javascript:{···}`): | |
– Tested in Chrome and Safari. | |
– Both browsers can handle URLs with multiple lines. |
const getterKey = Symbol('getterKey');
const setterKey = Symbol('setterKey');
const syncMethodKey = Symbol('syncMethodKey');
const syncGenMethodKey = Symbol('syncGenMethodKey');
const asyncMethodKey = Symbol('asyncMethodKey');
const asyncGenMethodKey = Symbol('asyncGenMethodKey');
function hyphenize(str) { | |
// /y is to make sure that there are no characters between the matches | |
// /g is so that .match() works the way we need here | |
// /u is not strictly necessary here, but generally a good habit | |
return str.match(/([a-z]{1,2})/uyg).join('-'); | |
} | |
assert.equal( | |
hyphenize('hello'), 'he-ll-o' | |
); |
/** | |
* This module contains two data structures: | |
* | |
* - `KeyContainerMap` lets us use “key containers” as Map keys. | |
* - `KeyContainerSet` lets us use “key containers” as Set elements. | |
* | |
* A “key container” is an object that has a method `.getMapKey()`. Two key | |
* containers are considered equal if `.getMapKey()` returns the same value | |
* (often a string). | |
* |