函数和对象 Javascript [英] Function and Object Javascript

查看:22
本文介绍了函数和对象 Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读 Stoyan Stefanov 写的名为Object Oriented Javascript"的书.我看到这句话:

I've been reading the book named "Object Oriented Javascript" by Stoyan Stefanov. I see this sentence:

function 实际上是一个用 'Function' 构造函数(大写 F)构建的对象.

function is actually an object that is built with 'Function' constructor function (with capital F).

作者用一些很好的例子证明了这一点.然而,基于那句话,我得到了这个我自己无法回答的问题.由于'Function'构造函数是一个函数,所以'Function'函数是一个对象,那么'Function'对象> 需要另一个构造函数来构建它,而另一个构造函数又是一个对象(因为它是一个函数).

The author demonstrates this with some nice examples. However, based on that statement, I got this question that can't be answer by myself. As 'Function' constructor is a function, so 'Function' function is an Object, then 'Function' object needs another constructor function to build it and that another constructor function is again an Object (because it's a function).

好吧,我最终得到了这个无穷无尽的逻辑.有人能帮我指出我想法中的错误点吗?

Well, I end up with this endless logic. Can someone help me point out the wrong point in my thinking?

推荐答案

'Function' 函数是一个对象,那么 'Function' 对象需要另一个构造函数来构建它

'Function' function is an Object, then 'Function' object needs another constructor function to build it

没有.Function 是一个原生的内置对象,其属性和行为在 EcmaScript 规范的第 15.3 节.它不是由 js 函数构建的.

No. Function is a native, builtin object whose properties and behavior are defined in section 15.3 of the EcmaScript specification. It was not built by an js function.

这样想:在您的 EcmaScript 环境代码中的某处有一个函数来构建函数对象——只要您的脚本遇到函数表达式或声明,就会调用它.全局 Function 函数是该函数的包装器,以便脚本可以访问它.该函数返回的所有函数对象都继承自 Function.prototype 对象 - 看起来它们是由 Function 构造的.还有所有函数继承的 Function.prototype.constructor 属性 被定义为指向Function.

Think of it like that: There is a function somewhere in the code of your EcmaScript environment that builds function objects - it is called whenever your script encounters a function expression or declaration. The global Function function is a wrapper for that function to make it accessible for scripts. All function objects which that function returns inherit from the Function.prototype object - it looks like they were constructed by Function. Also the Function.prototype.constructor property that all functions inherit is defined to point to Function.

这篇关于函数和对象 Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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