function isArray(o) {
    return Object.prototype.toString.call(o) === '[object Array]';
}

function isRegExp(o) {
    return Object.prototype.toString.call(o) === '[object RegExp]';
}

以上为示例,利用 Object.prototype.toString.call() 实现精确的类型判断;

相关文章: