Created
May 10, 2012 12:11
-
-
Save Meettya/2652639 to your computer and use it in GitHub Desktop.
why sugar is so sweet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# underscore.js | |
target[key] = if _.isArray val then [] else {} | |
# sugar.js | |
target[key] = if val?.isArray then [] else {} |
Oh, I get this line from full-sized worked CoffeeScript code, and its looks like broken, yap, sorry.
I re-check JS result, it compiled correctly without ()
(CS very smart in braces) but yes, val
need to be extended before test, I missed it.
Thanx for you comment.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think you need
()
onisArray
here.Also as much as I want to agree with the title of this gist, in this case, for most people at least, it should actually match underscore as you need to put either
Object.isArray(val)
orArray.isArray(val)
(the latter is ES5 standard).The above code is only valid if you explicitly map Object methods to the
Object.prototype
like this:This is easy enough but it's off by default as Sugar doesn't interfere with
Object.prototype
so as not to break stuff....