2015-02-17 46 views
0

我可以在JavaScript中识别以下几种类型:在JavaScript中函数是一个离散类型吗?

number, string, boolean, object, null and undefined 

但是,是function离散型,或者是它的object一个实例?

+4

函数是'Function'构造函数的实例。它们是具有特殊运行时支持特性的对象(如函数)。 – Pointy 2015-02-17 22:46:45

+0

'typeof'也认为'null'是'Object'类型,'undefined'实际上不是一个类型。 – Pointy 2015-02-17 22:47:27

+0

因此'typeof'的返回值对应于语言中类型的超集? – Ben 2015-02-17 22:53:26

回答

1

javascript中的函数是从Object继承的。您可以尝试以下操作:

var my_func = function(){}; 
console.log(my_func instanceof Object); // prints true 
console.log(my_func instanceof Function); // also prints true 

Array的情况也是如此。

相关问题