Is there a fast way of checking if an object is a jQuery object or a native JavaScript object?(有没有快速检查对象是jQuery对象还是本机JavaScript对象的方法?)
example:(例:)
var o = {};
var e = $('#element');
function doStuff(o) {
if (o.selector) {
console.log('object is jQuery');
}
}
doStuff(o);
doStuff(e);
obviously, the code above works but it's not safe.(显然,上面的代码有效,但不安全。) You could potentially add a selector key to the o
object and get the same result.(您可以将选择键添加到o
对象并获得相同的结果。) Is there a better way of making sure that the object actually is a jQuery object?(有没有更好的方法来确保对象实际上是一个jQuery对象?)
Something in line with (typeof obj == 'jquery')
(符合的东西(typeof obj == 'jquery')
)
ask by David Hellsing translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…