Last active
August 29, 2015 14:20
-
-
Save elierotenberg/a772e49914ca6ba12d12 to your computer and use it in GitHub Desktop.
isExtensionOf
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
// 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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Won't this line always return false?