日期:2014-05-16 浏览次数:21977 次
var box = new Object();
alert(box);
var a = {},
b = function(){},
c = [];
console.log(Object.prototype.toString.call(a)); //"[object Object]"
console.log(Object.prototype.toString.call(b)); //"[object Function]"
console.log(Object.prototype.toString.call(c)); //"[object Array]"
Object.prototype.toString = function(){
var s = '[object';
var test = [Function,Boolean,Number,String,Array,Date,Object];
var testMap = ['Function','Boolean','Number','String','Array','Date','Object'];
//s +=typeof this;
for(var i=0;i<test.length;i++){
if(this instanceof test[i]){
s +=' ' + testMap[i] + ']';
break;
}
}
return s;
}