封装type
//工具方法
function typePackaging (target){
//存储判断结果
var template = {
"[object Array]" : "array",
"[object Object]" : "object",
"[object Number]" : "number-object",
"[object Boolean]" : "boolean-object",
"[object String]" : "string-object"
}
if (target === null){
return "null";
}else if(typeof(target) == "object"){
var str = Object.prototype.toString.call(target);
return template[str];
}else{
return typeof(target);
}
}
数组去重
Array.prototype.unique = function (){
var temp = {},//利用对象属性名无法重复的性质
arr = [];
for(var i = 0; i < this.length; i++){
if(!temp[this[i]]){//判断对象是否已给此属性赋值
temp[this[i]] = "abc";
arr.push(this[i]);
}
}
return arr;
}