Skip to content

Instantly share code, notes, and snippets.

@jonchurch
Created August 19, 2019 18:46
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 jonchurch/06d09dd7a93307f0c365f6da7684e4c6 to your computer and use it in GitHub Desktop.
Save jonchurch/06d09dd7a93307f0c365f6da7684e4c6 to your computer and use it in GitHub Desktop.
Using instanceof without throwing on arrow functions
const arrow = () => true;
class ExampleClass {}
const classInst = new ExampleClass();
// this throws
try {
classInst instanceof arrow;
} catch (err) {
console.log("arrow has no prototype", err);
}
// this works without throwing
console.log(!!arrow.prototype && classInst instanceof arrow);
console.log(!!ExampleClass.prototype && classInst instanceof ExampleClass);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment