<分区>
// var = {hey: "baby"};
// or
// var = $('#thingy');
if(typeof var == 'object'){ // this is true for both =(
}
我需要我的代码足够智能,能够区分这两者。实现该目标的最佳方法是什么?
<分区>
// var = {hey: "baby"};
// or
// var = $('#thingy');
if(typeof var == 'object'){ // this is true for both =(
}
我需要我的代码足够智能,能够区分这两者。实现该目标的最佳方法是什么?
最佳答案
您可以为此使用 instanceof 运算符。
obj instanceof jQuery
此外,我认为您不想使用“var”作为变量名。保留建立变量作用域。
关于javascript - 如何区分常规对象和 jquery 对象(页面元素)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21768161/