Created
January 24, 2012 19:44
-
-
Save Raynos/1672142 to your computer and use it in GitHub Desktop.
Partial non-enumerable implementation
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
/* partial non-enumerable property implementation | |
Adds a flag to a weakmap saying on obj foo property bar is not enumerable. | |
Then checks that flag in Object.keys emulation. | |
*/ | |
// pd.Name :- https://github.com/Raynos/pd#pd.Name | |
var enumerables = pd.Name(); | |
Object.defineProperty = function (obj, name, prop) { | |
if (prop.enumerable === false) { | |
enumerables(obj)[name] = true; | |
} | |
... | |
}; | |
Object.keys = function (obj) { | |
var enumerabilityHash = enumerables(obj), keys = []; | |
for (var k in obj) { | |
if (obj.hasOwnProperty(k) && !enumerabilityHash[k]) { | |
keys.push(k); | |
} | |
} | |
return keys; | |
}; | |
Object.getOwnPropertyNames = function (obj) { | |
var keys = []; | |
for (var k in obj) { | |
if (obj.hasOwnProperty(k)) { | |
keys.push(k); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment