I am using NodeJS and going to write some utility functions. I think of two options here.
The first one is the traditional approach, i.e.
module.exports = {
random: () => Math.random(),
};
And the second option is to use ES6 class with static methods, e.g.
class MyMath {
static random() {
return Math.random();
}
}
module.exports = MyMath;
From programming/unit testing's perspective which one is better? Or they are pretty much the same because ES6 class essentially is a syntactic sugar?
Update: Thanks for the people who commented. I saw those questions asking class static method v.s. instance method, or prototype methods v.s. object method but mine is more like class static method v.s. Object method.