1.直接在原生Object原型下增加方法
Object.prototype.isTypeOf = function (f) {
var type = Object.prototype.toString.call(this);
if (f instanceof Function) {
f.call(this, type)
}
return type
}
2.使用方法
var arr = [
1,
{},
[],
function(){
},
RegExp,
'hello world',
];
for (let index = 0; index < arr.length; index++) {
const element = arr[index];
console.log(element.isTypeOf());
}
