javascript: remove redundant instanceof checks