Why do lodash's .isObject, .isPlainObject behave differently than “typeof x === 'object'”?
请考虑以下内容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | var o1 = {} var O = function () { return this } var o2 = new O() var o3 = function() {} var o4 = [o1, o1] var output = [ [_.isObject(o1), _.isObject(o2), _.isObject(o3), _.isObject(o4)], [_.isPlainObject(o1), _.isPlainObject(o2), _.isPlainObject(o3), _.isPlainObject(o4)], [typeof o1 === 'object', typeof o2 === 'object', typeof o3 === 'object', typeof o4 === 'object'], [o1 instanceof Array, o2 instanceof Array, o3 instanceof Array, o4 instanceof Array] ] /* outputs: [ [true,true,true,true], [true,false,false,false], [true,true,false,true], [false,false,false,true] ] */ |
很明显,我们可以看到
之间存在断开连接
Which checks if value is the language type of Object. (e.g. arrays, functions, objects, regexes, new Number(0), and new String(' ')
Which if value is a plain object, that is, an object created by the Object constructor or one with a Prototype of null
和我们的好朋友'x2>。
我有三个问题:
很明显,我可以继续使用
记录中涉及以下内容:
Checks if value is the language type of Object. (e.g. arrays, functions, objects, regexes, new Number(0), and new String(''))
哇!没有方便的
如果您关心
我相信这是您大部分的问题。我相信
n