Created
May 28, 2020 14:17
-
-
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
This file contains 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
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