首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >了解`Boolean.constructor`和`Boolean.constructor(true)`

了解`Boolean.constructor`和`Boolean.constructor(true)`
EN

Stack Overflow用户
提问于 2014-05-25 10:37:28
回答 1查看 27关注 0票数 0

查看Boolean.constructor

代码语言:javascript
复制
var bool = true;
var booleanObj = new Boolean(true);
console.log ('typeof bool', typeof bool);             # returns 'boolean'
console.log ('typeof booleanObj', typeof booleanObj); # returns 'object'

下面的代码行返回:function Function() { [native code] }。如何查看native code

代码语言:javascript
复制
console.log('Boolean.constructor', Boolean.constructor);

最后,我怎样才能

代码语言:javascript
复制
var y = Boolean.constructor(true);
console.log('typeof y', typeof y); # returns function

然后,输出yy: function anonymous() { true }。如何解压true

代码语言:javascript
复制
console.log('y:', y);

http://jsfiddle.net/9YxkE/

EN

回答 1

Stack Overflow用户

发布于 2014-05-25 10:38:31

Boolean是一个函数。

它的constructor属性是所有函数(即Function函数)的构造函数。

本机代码是Javascript引擎的一部分,通常用C++编写。

如果您愿意,您可以探索V8或SpiderMonkey的源代码。

true是通过调用Function构造函数创建的函数体。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23851499

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档