jQuery获取对象类型字符串的代码,有一句看不懂,求解?
jQuery获取对象类型字符串,这段代码是什么意思?class2type[ toString.call( obj ) ]
不理解这句话的作用是什么?
var class2type = {};
var toString = class2type.toString;
function toType( obj ) {
if ( obj == null ) {
return obj + "";
}
return typeof obj === "object" ?
class2type[ toString.call( obj ) ] || "object" :
typeof obj;
}
回复
1个回答
test
2024-06-29
class2type.toString
就是 Object.prototype.toString
这段代码里没得给 class2type
添加属性,所以看不出来 class2type[ toString.call( obj ) ]
是什么意思 ……
把填充字典的那部分代码找出来就知道了
回复
适合作为回答的
- 经过验证的有效解决办法
- 自己的经验指引,对解决问题有帮助
- 遵循 Markdown 语法排版,代码语义正确
不该作为回答的
- 询问内容细节或回复楼层
- 与题目无关的内容
- “赞”“顶”“同问”“看手册”“解决了没”等毫无意义的内容