I've come across this syntax a couple times in different contexts and wonder what it means. My guess is shown below.
From https://cerebraljs.com/docs/introduction/the_architecture.html
connect({
userName: state`auth.user.info.name`
})(function User(props) {
props.userName // "some name" (value stored in 'app.user.name')
})
The syntax state`auth.user.info.name` is what I'm asking about.
Another piece of I code I found that uses it is shown below (changed slightly to show what I think the code does):
// import styled from './styles';
var styled = {};
styled.div = function(x) { console.log('x is', x);};
var Buttons = styled.div`
display: flex;
justify-content: center;
margin-top: 1rem;
button {
display: flex;
justify-content: center;
width: 6rem;
margin: 0.5rem;
}
`;
When I copy the above into my code snippet into my browser console, I see that syntax styled.div`long string` simply calls the function styled.div
with the string `bar` as such foo('bar')
(backticks replaced with normal tick due to formatting issues)
Sidebar: Trying to put backticks/backquotes into a question is amazingly difficult in StackOverflow because SO wants to style the string as code and removes the backticks... but I digress.
So is my understanding of what the code does correct?
Is this simply a way to pass a string to a function without writing the open and close parenthesis? Or is there more to this syntax, like the Javascript IIFE syntax.
When searching on SO I found several questions about Javascript syntax, but did not find this one answered.