var emptyObj = {}; //空對(duì)象var notEmptyObj = {"age":"one"}; //非空對(duì)象window.console.info($.isEmptyObject(emptyObj));//輸出truewindow.console.info($.isEmptyObject(notEmptyObj));//輸出false我們都知道,通過(guò)$.isEmptyObject()可以判斷一個(gè)JS對(duì)象是否為空但閱讀JQuery源碼,發(fā)現(xiàn)這個(gè)方法只是對(duì)Obj進(jìn)行了遍歷,然后return false并沒(méi)有進(jìn)行空或者null的判斷啊,這是怎么做到的?$.isEmptyObject: function( obj ) { var name; for ( name in obj ) { return false; } return true;}
為什么JQuery.isEmptyObject()可以判斷空對(duì)象
牧羊人nacy
2018-09-06 10:10:21