get.js 567 B

123456789101112131415161718192021222324
  1. export default (function get(object, property, receiver) {
  2. if (object === null) object = Function.prototype;
  3. var desc = Object.getOwnPropertyDescriptor(object, property);
  4. if (desc === undefined) {
  5. var parent = Object.getPrototypeOf(object);
  6. if (parent === null) {
  7. return undefined;
  8. } else {
  9. return get(parent, property, receiver);
  10. }
  11. } else if ("value" in desc) {
  12. return desc.value;
  13. } else {
  14. var getter = desc.get;
  15. if (getter === undefined) {
  16. return undefined;
  17. }
  18. return getter.call(receiver);
  19. }
  20. });