Difference between jQuery.isPlainObject () and jQuery.isEmptyObject ()

Can someone explain what is the difference between jQuery.isPlainObject () and jQuery.isEmptyObject ()? They both return true for an object that has no properties. Examples

jQuery.isEmptyObject({}); // returns true
jQuery.isPlainObject({}); // returns true

Thanks in advance.

+5
source share
2 answers

$.isEmptyObject()does not take into account the type of object or its creation; if it has absolutely no properties, this function returns true.

$.isPlainObject()returns true for objects that are pure instances Object; false for objects that have some other type, for example. Number, String, FunctionOr user-defined type.


The manual for $.isPlainObject():

: , ( "{}" " " ).

{} true, Object. , $.isEmptyObject() true.

+13
jQuery.isEmptyObject()

true, ( ).

jQuery.isPlainObject()

true, () "new Object()".

:

jQuery.isEmptyObject({ 'try' : 'this' }); // returns false
jQuery.isPlainObject({ 'try' : 'this' }); // returns true
+5

All Articles