dianping/cat · error · TypeError
typeof prototype[{typeof prototype}] != 'object'
Error message
typeof prototype[{typeof prototype}] != 'object' What it means
This is the es5-shim polyfill for Object.create bundled into worker-xquery.js. ES5 spec requires the first argument (the prototype) to be an object or null; the shim explicitly throws a TypeError with a diagnostic that embeds the actual typeof when a primitive is passed. Native engines throw a vaguer error, so this message is a shim-specific improvement.
Source
Thrown at cat-home/src/main/webapp/assets/js/editor/worker-xquery.js:49293
empty.constructor =
empty.hasOwnProperty =
empty.propertyIsEnumerable =
empty.isPrototypeOf =
empty.toLocaleString =
empty.toString =
empty.valueOf =
empty.__proto__ = null;
return empty;
}
}
Object.create = function create(prototype, properties) {
var object;
if (prototype === null) {
object = createEmpty();
} else {
if (typeof prototype != "object")
throw new TypeError("typeof prototype["+(typeof prototype)+"] != 'object'");
var Type = function () {};
Type.prototype = prototype;
object = new Type();
object.__proto__ = prototype;
}
if (properties !== void 0)
Object.defineProperties(object, properties);
return object;
};
}
function doesDefinePropertyWork(object) {
try {
Object.defineProperty(object, "sentinel", {});
return "sentinel" in object;
} catch (exception) {
}
}View on GitHub (pinned to e815e74d4c)
Solutions
- Check the value passed as prototype: it must be an object, a function (use MyCtor.prototype), or explicitly null.
- If you want an empty dictionary-style object, use Object.create(null), not Object.create(undefined) or Object.create({}) with a missing variable.
- Trace the argument upstream — this message tells you the runtime type, so log the variable before the call to find where it became a primitive.
- If the call is inside a third-party library, update it: newer builds may already guard against primitives.
Example fix
// before
var proto = config.baseProto; // may be undefined/string
var obj = Object.create(proto);
// after
var proto = config.baseProto;
if (proto !== null && (typeof proto !== 'object' && typeof proto !== 'function')) {
throw new TypeError('config.baseProto must be an object or null, got ' + typeof proto);
}
var obj = Object.create(proto); Defensive patterns
Strategy: type-guard
Validate before calling
function isValidPrototype(p) {
return p === null || (typeof p === 'object') || (typeof p === 'function');
}
if (!isValidPrototype(proto)) throw new Error('bad prototype: ' + typeof proto);
var obj = Object.create(proto); Type guard
function isPrototypeOrNull(p) {
return p === null || typeof p === 'object' || typeof p === 'function';
} Prevention
- Always pass MyCtor.prototype, not the constructor or its name string
- Use Object.create(null) explicitly for prototype-less objects
- Log typeof of dynamic prototypes during development
When it happens
Trigger: Calling Object.create with a non-object, non-null first argument: Object.create('foo'), Object.create(42), Object.create(undefined), Object.create(false). Often happens when a variable expected to hold a prototype object is actually a string/number (e.g. reading a config value or a JSON-parsed value that came back as a scalar).
Common situations: Passing a class name or constructor name string instead of the constructor's .prototype; passing undefined because a lookup returned nothing; old browsers (IE8) where the shim is active and library code assumed an object was present.
Related errors
- Object.defineProperty called on non-object: {object}
- Property description must be an object: {descriptor}
- can't convert {o} to object
- {fun} is not a function
- reduce of empty array with no initial value
AI-assisted analysis of dianping/cat@e815e74d4c (2026-08-14).
Data as JSON: /api/errors/adff23f72262e358.
Report an issue: GitHub.