Skip to content

Instantly share code, notes, and snippets.

@elierotenberg
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elierotenberg/a772e49914ca6ba12d12 to your computer and use it in GitHub Desktop.
Save elierotenberg/a772e49914ca6ba12d12 to your computer and use it in GitHub Desktop.
isExtensionOf
// is A an extension of B ?
// ex:
// class C extends Oject {}
// class B extends C {}
// class A extends B {}
// isExtension(A, B) === true
// isExtension(A, C) === true
// isExtension(A, Object) === true
// isExtension(B, A) === false
function isExtensionOf(A, B) {
if(A === B) {
return true;
}
if(typeof A !== 'function') {
return false;
}
if(typeof B !== 'function') {
return A.__proto__ === B;
}
return isExtensionOf(A.__proto__, B);
}
@alexkirsz
Copy link

Won't this line always return false?

@elierotenberg
Copy link
Author

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment