return !!( proto === null || proto.constructor === Object );
return !!( proto === null || proto.constructor === Object );
只是想理解,后面的行应该返回什么以及如果proto.constructor = Object
怎么办?
return !!( proto === null || proto.constructor === Object );
更具体地说,!!
是如何工作的?
它将返回一个布尔值:true或false。 !!
就像双翻转一样:如果一个值为假,则将其翻转为真,然后将其翻转回假。基本上,有!!
和没有!!
是一样的。
如果proto === null
或proto.constructor === Object
,则为 true。
错误的 iff proto !== null
和 proto.constructor !== Object
.
因此,如果proto.constructor = Object
,它将返回 true。
!
(逻辑 NOT)运算符
如果其单个操作数可以转换为 true,则返回 false;否则,返回 true。(MDN)
一个 typeError。 因为 proto 没有定义并且不等于 null,所以 js 会尝试从不存在的 proto 中获取属性"constructor"。
相关文章:
- 函数未在Object.keys或Object.getOwnPropertyNames下列出,但可以调用
- delete在Object上效率低下,但在DOM Element's的数据属性,与null out相比
- 有没有一种方法可以列出Ember.Object的所有绑定
- 如何取消object.prototypes javascript的一个函数
- 为什么是文档.旧版应用程序中的DOM-object.properties为null
- 将*.js文件的内容放入Object中
- Object.prototype using 'this'
- 使用Object.create()的角度服务继承
- 如何使用object.assign()从其他对象引用基本对象属性
- 循环的数组推入在Object容器中具有不同的值
- reducers在redux中得到Function not Object,what'it’他错了
- JSON.stringify和Object.keys在同一个对象上产生不同的结果
- 在使用object.create创建的对象中使用super
- Join架构验证:Join.object定义数组中的有效键
- jquery打印[object XMLDocument]而不是文件内容
- ExtJS 4 Object.prototype fail
- JavaScript-从对象数组中输出随机OBJECT
- 为什么“{}+1”在Chrome和Firefox中排名第一,而字符串'[object object]1'
- return !!( proto === null || proto.constructor === Object );
- proto link和Object.create的区别