— Non-ducktyping version of this would be: e.g. typeof parameter == 'whatever'
— But that's kind of bad practice in languages with duck-typing, since it means you can't easily subclass/add behaviour
Message permanent page
— Or instanceof or isPrototypeOf
— Complex duck typing can also validate functions, I think
— But that's more unit-testy and less production
— Well, instanceof would still work in JS:
class MyError extends SyntaxError {
...
}
new TypeError() instanceof Error // true
new MyError() instanceof Error // true
Message permanent page
— I'm getting buffer.alloc is not a function error when I try to install using npm