Last active
November 27, 2021 16:50
-
-
Save Goldziher/79931ec9267370a0cec2afe1e1e5840e to your computer and use it in GitHub Desktop.
Duck typing in javascript
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
function isDuck(value) { | |
return !!( | |
value && | |
typeof value === 'object' && | |
typeof Reflect.get(value, 'quack') === 'function' | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment