Last active
October 10, 2023 17:26
-
-
Save darcher-/1568fa33b20c373d75d74766ab481f11 to your computer and use it in GitHub Desktop.
a look back at the evolution of string "merging" in javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** EXAMPLE */ | |
//? start | |
//* legacy | |
var prefix = 'x' | |
var infix = 'y' | |
/** suffix argument */ | |
var affix = 'id="'; | |
affix += prefix + '-'; | |
affix += infix + '-'; | |
if (suffix !== null && typeof suffix !== 'undefined') | |
affix += newSuffix(); | |
else | |
affix += 'z'; | |
affix += '"'; | |
//* outdated | |
var prefix = 'x' | |
var infix = 'y' | |
/** suffix param */ | |
suffix = !Boolean(suffix) ? newSuffix() : 'z'; | |
let affix = prefix + '-' + infix + '-' + suffix; | |
affix = 'id="' + affix + '"'; | |
//* depreciated | |
const prefix = 'x' | |
const infix = 'y' | |
/** suffix arg */ | |
const affix = `id="${[ | |
prefix, | |
infix, | |
suffix || newSuffix() || 'z' | |
].join('-')}"`; | |
//* modern | |
const prefix = 'x' | |
const infix = 'y' | |
/** suffix prop (defaults to "z") */ | |
const affix = `id="${prefix}-${infix}-${ | |
suffix ??= newSuffix() | |
}"`; | |
// -> String(id="x-y-z") | |
//! end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment