get-prototype-descriptors

Gather descriptors from constructor's prototype chain

Usage no npm install needed!

<script type="module">
  import getPrototypeDescriptors from 'https://cdn.skypack.dev/get-prototype-descriptors';
</script>

README

get-prototype-descriptors

Build Status npm version Greenkeeper badge

Returns all descriptors of a prototype chain while respecting prototype inheritance.

Installation

npm install --save get-prototype-descriptors

Usage

class A {
  one() {}
  get getterOnA() {
    return 'A';
  }
}

class B extends A {
  two() {}
  get getterOnA() {
    return 'B';
  }
}

class C extends B {
  three() {}
  get getterOnC() {
    return 'C'
  }
}

import getPrototypeDescriptors from 'get-prototype-descriptors';

let descriptors = getPrototypeDescriptors(C);

The descriptors will be flattened and descriptors from child classes will overload those of the parent.

Compatibility

get-prototype-descriptors requires Object.getOwnPropertyDescriptors which is not available in IE and pre-Node 6. You may consider adding a polyfill if you need to support these environments.

License

MIT License