Skip to content

Instantly share code, notes, and snippets.

@kl0tl
Created June 8, 2014 14:44
Show Gist options
  • Save kl0tl/a60d018b37d51ef577b9 to your computer and use it in GitHub Desktop.
Save kl0tl/a60d018b37d51ef577b9 to your computer and use it in GitHub Desktop.
Inline `Object.keys` (seems slower with Firefox)
let keys = macro {
rule infix { Object. | () } => { Object.keys() }
rule infix { Object. | ($object:expr) } => {
(function (object) {
if (typeof obj !== 'object' && (typeof obj !== 'function' || obj === null)) {
throw new TypeError('Object.keys called on non-object');
}
var keys = [], proto = object.__proto__;
object.__proto__ = null;
for (var key in object) {
keys.push(key);
}
object.__proto__ = proto;
return keys;
}($object))
}
rule { $rest ... } => { keys $rest ... }
}
export keys;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment