7
Currently I own this object:
const messages = {
required: field => `${field} é obrigatório e naõ foi preenchido!`,
}
That prints the following value:
name é obrigatório e não foi preenchido!
I need to apply a condition to this string template that changes the field value based on a condition. I tried something like:
const messages = {
required: field => `
${field => {
if(field === 'name') {
'nome'
}
if(field === 'address') {
'endereço'
}
}} é obrigatório e não foi preenchido
`,
}
But when I print I get:
field => { if(field === 'name') { return 'nome' } } é obrigatório e não foi preenchido
And I need:
nome é obrigatório e não foi preenchido.
A question I always ask for people who are more recently and have already caught the time of CSS3+ and ES6, is it really necessary? In both CSS3 and ES6 I know there are a lot of things that look cool, but do we really need them? For example, the other day asked how to put a CSS drawing as bg below each TD, formulated an advanced and complex response, but a simple SVG image with background-image would solve and work even better ...
– Guilherme Nascimento
... The same goes for template strings, do you really need to put logic inside the string? Wouldn’t it be better to set a var to each IF and then play in the template already handled? Do we need all this complexity? Why not the simplest and most intuitive? ... I honestly think that JS and CSS have created cool things, but not everything is actually useful, it actually seems to get in the way more.
– Guilherme Nascimento
Young man, putting expressions inside a template string makes it very difficult to read. Maybe we should rethink how to create this string.
– Wallace Maxters
@Guilhermenascimento thanks for the tips
– veroneseComS