Last active
June 6, 2020 22:46
-
-
Save yudium/e9da944725e5a0a150f038b1fef7d6c5 to your computer and use it in GitHub Desktop.
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
// 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