function isPlainObject(val) {
  if (toString.call(val) !== '[object Object]') {
    return false;
  }

  var prototype = Object.getPrototypeOf(val);
  return prototype === null || prototype === Object.prototype;
}
Determine if a value is a plain Object

@param {Object} val The value to test
@return {boolean} True if value is a plain Object, otherwise false