1'use strict' 2 3module.exports.isObjectProto = isObjectProto 4function isObjectProto (obj) { 5 return obj === Object.prototype 6} 7 8const _null = {} 9const _undefined = {} 10const Bool = Boolean 11const Num = Number 12const Str = String 13const boolCache = { 14 true: new Bool(true), 15 false: new Bool(false) 16} 17const numCache = {} 18const strCache = {} 19 20/* 21 * Returns a useful dispatch object for value using a process similar to 22 * the ToObject operation specified in http://es5.github.com/#x9.9 23 */ 24module.exports.dispatchableObject = dispatchableObject 25function dispatchableObject (value) { 26 // To shut up jshint, which doesn't let me turn off this warning. 27 const Obj = Object 28 if (value === null) { return _null } 29 if (value === undefined) { return _undefined } 30 switch (typeof value) { 31 case 'object': return value 32 case 'boolean': return boolCache[value] 33 case 'number': return numCache[value] || (numCache[value] = new Num(value)) 34 case 'string': return strCache[value] || (strCache[value] = new Str(value)) 35 default: return new Obj(value) 36 } 37} 38