Skip to content

Instantly share code, notes, and snippets.

@yudium
Last active June 6, 2020 22:46
Show Gist options
  • Save yudium/e9da944725e5a0a150f038b1fef7d6c5 to your computer and use it in GitHub Desktop.
Save yudium/e9da944725e5a0a150f038b1fef7d6c5 to your computer and use it in GitHub Desktop.
// These are equivalent:
myFunc`some string here`
myFunc(['some string here'])
// ----------------------------------
const aVar = 'good'
// These are equivalent:
myFunc`this is a ${aVar} day`
myFunc(['this is a ', ' day'], aVar)
// ----------------------------------
// These are equivalent:
myFunc`
background-color: ${props => props.primary ? "blue" : "grey"};
font-size: 20px;
`
myFunc([
'background-color: ',
${props => props.primary ? "blue" : "grey"},
'\n; font-size: 20px'
])
// Then this is how we define our MyFunc function:
function myFunc($args) {
css = "";
for (const argument of args){
if (typeof argument === 'function') {
css = css + argument() // call then concat result string
} else {
css = css + argument // concat string
}
}
return css;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment