I am reading this answer: https://stackoverflow.com/a/632914/840992 and I don't understand why one would define the function as a var
:
var setPrecision:Function = function(number:Number, precision:int) {
precision = Math.pow(10, precision);
return Math.round(number * precision)/precision;
}
var number:Number = 10.98813311;
trace(setPrecision(number,1)); //Result is 10.9
trace(setPrecision(number,2)); //Result is 10.98
trace(setPrecision(number,3)); //Result is 10.988 and so on
Rather than just a function:
public function setPrecision(number:Number, precision:int) {
precision = Math.pow(10, precision);
return Math.round(number * precision)/precision;
}
I am using classes for everything. I can understand it if one wanted to pass the var
around, etc. but as just a utility to set float precision, I am not seeing the value here. All of the related questions I have seen pertain to JavaScript.
Am I correct in thinking that in a class, there is no good reason for defining this function as a var
?