为什么:
console.log( typeof String );
function
当它是一个对象时返回?
字符串是字符串对象的构造函数。所有构造函数都是函数,因此您将看到返回值。
您可以通过创建如下代码来自己查看:
var MyObject = function (value) {
this.value = value;
};
MyObject.prototype.getValue = function () {
return this.value;
}
console.log(typeof(MyObject)); // function
console.log(typeof(new MyObject(1))); // object
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句