Skip to content

Instantly share code, notes, and snippets.

@Raynos
Created January 24, 2012 19:44
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Raynos/1672142 to your computer and use it in GitHub Desktop.
Save Raynos/1672142 to your computer and use it in GitHub Desktop.
Partial non-enumerable implementation
/* 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