You do realize that both end up compiling into the "same" code right? The only thing that reduces the file size is the {}.toString instead of using Object.prototype.toString (14 bytes) but with the cost of creating a new Object instance just to get the reference to the method... and the other stuff (ternary, returns) makes code harder to read:
I keep the named function with the return at the bottom because sometimes people might need the same method but on a non-AMD context, so copy and paste and an automated process works well.
Also notice that "" + UNDEF will give "undefined" while the older version would return "Undefined" (capital "U").
You do realize that both end up compiling into the "same" code right? The only thing that reduces the file size is the
{}.toString
instead of usingObject.prototype.toString
(14 bytes) but with the cost of creating a new Object instance just to get the reference to the method... and the other stuff (ternary, returns) makes code harder to read:Original
Yours
Minified using closure compiler.
I keep the named function with the
return
at the bottom because sometimes people might need the same method but on a non-AMD context, so copy and paste and an automated process works well.Also notice that
"" + UNDEF
will give"undefined"
while the older version would return"Undefined"
(capital "U").Ignoring it since it's premature optimization.