是
if(!!object)
{
// do something if object found
}一种更有保障的方式来查看是否存在任何对象?
if(object)
{
}发布于 2012-05-24 22:10:28
检查某物是否已定义的最安全方法:
if (typeof thingy !== 'undefined')发布于 2012-05-24 22:14:44
if(typeof my_var == 'object'){
}发布于 2012-05-24 22:21:05
有很多方法可以检查……
if ( object )
if ( !!object )
if ( object !== undefined )
if ( typeof object !== 'undefined' )
if ( object !== void 0 )
if ( {}.toString.apply( object ).subtr( 0, 7 ) === '[object' )等。
https://stackoverflow.com/questions/10739130
复制相似问题