7
I have the following code:
scope.cm = 1;
scope.mm = 2;
scope.km = 3;
tipoDeMedida[scope.cm || scope.mm || scope.km] = function(arrayQualquer){
//executo meu bloco de código X.
}
tipoDeMedida[scope.km](arrayQualquer)
I’m getting the following error output:
tipoDeMedida[scope.km] is not a function
From what I understand, in the function of the first block of code, you are not accepting the OR operator for each type of data that I am trying to pass on. I wonder if there is some elegant way to solve this problem without having to do a function for each type of data(I don’t want to run block X three times).
I don’t quite understand what you want to do, but if you do
var tipoMedida = function(tipo, arrayQualquer)and pass astipoMedida(scope.km, arrayQualquer)doesn’t solve?– Pliavi
It does... I’ll even do it. I only asked because the pattern of the system in question is the one that I showed, so you will have to refactor a lot in this solution.But I wanted to understand why he is not recognizing the other values....
– fernandoocf
Ah, yes, it doesn’t work because
||(or) is Boolean, is 1, 2 or 3, and other languages that would generate atrue, but from what I’ve seen js tend to use only the first value informed, possibly you would have only the cm– Pliavi
got it... you’re right! I tested it here and that’s exactly what’s going on. The value of Scope.cm will always exist, so it will never fall into the next condition....
– fernandoocf