Skip to content

Instantly share code, notes, and snippets.

@aduth
Last active December 12, 2015 03:39
Show Gist options
  • Save aduth/4708978 to your computer and use it in GitHub Desktop.
Save aduth/4708978 to your computer and use it in GitHub Desktop.
Object.keys shim (non-spec-compliant): JavaScript vs CoffeeScript
// 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