[quote user="Chris F"][quote user="treefrog"]If I'm reading the code and I see 'num.toFixed(2)', I'm pretty certain I know what's going to happen. Is it really necessary to type roundNumber(num,2)? If another developer has to inherit the code (which is where I'm at), and there's an error with that function, I'm going to have to hunt it down and figure out what's going on. If the intent is to round to the specified digits - just do it.[/quote]
It does something different than num.toFixed, though. While the current function is not ideal, its problems do not arise from its granularity. There are actually a few idioms encapsulated there, such as the type conversions and fallback values. I would have made the method even more granular by encapsulating the type conversion with fallback to a default value idiom as a function as well.[/quote]
The additional work that's being done here such as the type conversion and the fallback are unnecessary if the Number object's toFixed method is used...because you're already operating on a number and it has a default of 0 if you don't supply an argument.
[quote user="Chris F"]The overhead and memory here is trivial. Namespace pollution is not a very convincing argument either, because JavaScript has some very flexible structuring mechanisms - you can even place your extension methods directly on the built-in classes you extend, which is great. Contains, isVowel and roundNumber are clearly doing more than the built-in methods already provide.[/quote]
I probably should have given more context to my WTF - What I didn't share is that this is SSJS - not Client-side. Some of these files have so many "includes" that I've seen processor usage spike to 25%+ just to load a simple form. While I agree that one or two functions that wrap some built-in methods are probably fine; there are hundreds of "extra" functions like this scattered throughout the application. The WTF, to me, is that these type of one-liner functions (except maybe isVowel) that give a different name to built-in object methods are a waste to type, use, and track down when something goes wrong.