Created
June 8, 2014 14:44
-
-
Save kl0tl/a60d018b37d51ef577b9 to your computer and use it in GitHub Desktop.
Inline `Object.keys` (seems slower with Firefox)
This file contains hidden or 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
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