0
What is most recommended?
In a situation I can use both modes (I can choose, it will work the same way).
What is recommended to do? Create a role or insert the script directly into the JS file?
Basic example:
if(2*5 == 10){
console.log('Verdade!');
}
Or
function conta() {
if(2*5 == 10){
console.log('Verdade!');
}
}
conta();
That was just an example, but summarize what I want to know.
Once again, I reinforce that I know that in certain places I won’t be able to create the code directly because it won’t make sense and errors will occur, but there are some things so small that in everyday life we need to do, which I would like to know which way is recommended, if there is something in the processing speed, etc...
If this question is based on opinions, I’m sorry!
I think it’s kind of personal opinion, but I would say that if you’re going to use the same code in more than one place: create a function to stay more DRY
– Sergio
You can give an example of these "things so small that in everyday life we need to do" to better understand what kind of things are ?
– Isac
Each case has its peculiarities and, as it is not a real example, it is difficult to answer.
– Woss
Isac, I work for example in a company that is an E-commerce, and another company provides a Magento Saas for us, that is, I do not have access to Backend and in some pages also of the same, and sometimes I need to change for example, text of some buttons (example this). I simply take jQuery $('.myClass'). text('New name') or should I create a function? Even though I don’t need to reuse that code again.
– Lucas de Carvalho