Skip to content

Instantly share code, notes, and snippets.

@stand-sure
Created May 28, 2020 14:17
Show Gist options
  • Save stand-sure/cd54255dabf8c9a868cb494b5593ef96 to your computer and use it in GitHub Desktop.
Save stand-sure/cd54255dabf8c9a868cb494b5593ef96 to your computer and use it in GitHub Desktop.
determines if the shape of an object's prototype is the same as the shape of another object
const isSubclassOf = function isSubclassOf(derived: any, base: any) {
const pair = [Reflect.getPrototypeOf(derived), base];
const allKeys = pair.reduce(
(keys, instance) => keys.concat(Object.keys(instance)),
[]
);
const distinctKeys = new Set(allKeys);
return distinctKeys.size === Object.keys(base).length;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment