Created
August 16, 2012 20:42
-
-
Save WebReflection/3373484 to your computer and use it in GitHub Desktop.
Object.getPropertyDescriptor and Object.getPropertyNames
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
!function(Object, getPropertyDescriptor, getPropertyNames){ | |
// (C) WebReflection - Mit Style License | |
if (!(getPropertyDescriptor in Object)) { | |
var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; | |
Object[getPropertyDescriptor] = function getPropertyDescriptor(o, name) { | |
var proto = o, descriptor; | |
while (proto && !( | |
descriptor = getOwnPropertyDescriptor(proto, name)) | |
) proto = proto.__proto__; | |
return descriptor; | |
}; | |
} | |
if (!(getPropertyNames in Object)) { | |
var getOwnPropertyNames = Object.getOwnPropertyNames, ObjectProto = Object.prototype, keys = Object.keys; | |
Object[getPropertyNames] = function getPropertyNames(o) { | |
var proto = o, unique = {}, names, i; | |
while (proto != ObjectProto) { | |
for (names = getOwnPropertyNames(proto), i = 0; i < names.length; i++) { | |
unique[names[i]] = true; | |
} | |
proto = proto.__proto__; | |
} | |
return keys(unique); | |
}; | |
} | |
}(Object, "getPropertyDescriptor", "getPropertyNames"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment