This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 复制对象 | |
* @param: obj {JavaScript Object} 原始对象 | |
* @param: isDeep {Boolean} 是否为深拷贝 | |
* @return: {JavaScript Object} 返回一个新的对象 | |
*/ | |
function copy(obj, isDeep) { | |
var ret = obj.slice ? [] : {}, p; | |
// 配合 is 函数使用 | |
if(!isDeep && is(obj, 'Array')) return obj.slice(); | |
for(p in obj) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 检测对象类型 | |
* @param: obj {JavaScript Object} | |
* @param: type {String} 以大写开头的 JS 类型名 | |
* @return: {Boolean} | |
*/ | |
function is(obj, type) { | |
return Object.prototype.toString.call(obj).slice(8, -1) === type; | |
} |
NewerOlder