/** * Created by W.X. on 2016/11/23. */ /** * 用来检查 item 是否某种类型 * @param item 目标item * @param type 要匹配的类型, 可以是字符串, 某类型的实例元素或构造函数 * @returns {boolean} */ export const checkItemType = (item, type) => { //如果要匹配的是字符串,则看构造函数的名称 if (typeof(type) === 'string'){ const itemTypeName = item.constructor.name; return itemTypeName === type; } else { const typeName = type.constructor.name; if (typeName === 'Function'){ return item instanceof type; } else { return item.constructor.name === typeName; } } };