在JavaScript中,为什么typeof Function.prototype是“function”,而不是“object”。像其他原型对象? [英] In JavaScript, why typeof Function.prototype is "function", not "object" like other prototype objects?

查看:157
本文介绍了在JavaScript中,为什么typeof Function.prototype是“function”,而不是“object”。像其他原型对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

console.log(typeof String.prototype); // object
console.log(typeof Number.prototype); // object
console.log(typeof Object.prototype); // object
console.log(typeof Boolean.prototype); // object

console.log(typeof Function.prototype); // function

为什么 typeof Function.prototype 返回功能,而不是像其他原型对象一样的对象?

Why does typeof Function.prototype return "function", not "object" like other prototype objects?

谢谢!

推荐答案

这似乎是在 ECMAScript 5 中定义的:

This seems to be defined in ECMAScript 5:


15.3.4函数原型对象的属性

Function原型对象本身就是一个Function对象(它的 [[Class]] Function),当被调用时,它接受任何参数和返回未定义

The Function prototype object is itself a Function object (its [[Class]] is "Function") that, when invoked, accepts any arguments and returns undefined.

这篇关于在JavaScript中,为什么typeof Function.prototype是“function”,而不是“object”。像其他原型对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆