Last active
December 12, 2015 03:39
-
-
Save aduth/4708978 to your computer and use it in GitHub Desktop.
Object.keys shim (non-spec-compliant): JavaScript vs CoffeeScript
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
// JavaScript | |
if (Object.keys == null) { | |
Object.keys = function(obj) { | |
var keys = []; | |
for (var key in obj) { | |
if (obj.hasOwnProperty(key)) { | |
keys.push(key); | |
} | |
} | |
return keys; | |
} | |
} | |
# CoffeeScript | |
Object.keys ?= (obj) -> | |
key for key of obj when obj.hasOwnProperty(key) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment