mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
I've reverted match properties that return class instances back to normal functions, so that they can be called as constructors. Also, I added tests to make sure we catch this issue if someone else gets the same idea that I had!
37 lines
945 B
JavaScript
37 lines
945 B
JavaScript
// Copy of jQuery.isPlainObject for the server side from jQuery v3.1.1.
|
|
|
|
const class2type = {};
|
|
|
|
const toString = class2type.toString;
|
|
|
|
const hasOwn = Object.prototype.hasOwnProperty;
|
|
|
|
const fnToString = hasOwn.toString;
|
|
|
|
const ObjectFunctionString = fnToString.call(Object);
|
|
|
|
const getProto = Object.getPrototypeOf;
|
|
|
|
export const isPlainObject = obj => {
|
|
let proto;
|
|
let Ctor;
|
|
|
|
// Detect obvious negatives
|
|
// Use toString instead of jQuery.type to catch host objects
|
|
if (!obj || toString.call(obj) !== '[object Object]') {
|
|
return false;
|
|
}
|
|
|
|
proto = getProto(obj);
|
|
|
|
// Objects with no prototype (e.g., `Object.create( null )`) are plain
|
|
if (!proto) {
|
|
return true;
|
|
}
|
|
|
|
// Objects with prototype are plain iff they were constructed by a global Object function
|
|
Ctor = hasOwn.call(proto, 'constructor') && proto.constructor;
|
|
return typeof Ctor === 'function' &&
|
|
fnToString.call(Ctor) === ObjectFunctionString;
|
|
};
|