Better detect real plain object, copy over directly class object.
The function isPlainObject is copied from jQuery.