public
Last active

Partial non-enumerable implementation

  • Download Gist
partial.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
/* 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);
}
}
};

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.