简体   繁体   English

任何JS引擎如何用JavaScript创建内置对象(例如:“对象”)?

[英]How are built-in objects (ex: 'Object') created in Javascript by any JS engine?

In Javascript there are many built-in objects (ex: Object,Number,Array,Math) which are ready to be Cloned/Prototyped to create our own custom objects. 在Javascript中,有许多内置对象(例如:Object,Number,Array,Math)可以被克隆/原型化以创建我们自己的自定义对象。

I understand how the custom objects inherit built-in objects. 我了解自定义对象如何继承内置对象。 'Object' object is on top of the inheritance chain. “对象”对象位于继承链的顶部。

How is this 'Object' object created in memory in the first place? 首先如何在内存中创建“对象”对象? Who creates it? 谁创造的?

Can anyone please explain this with example of any JS engine? 谁能用任何JS引擎的例子来解释这一点? (V8 engine preferably). (最好是V8引擎)。 Thanks in Advance!! 提前致谢!!

Javascript engine creates the 'Object' object. JavaScript引擎会创建“对象”对象。 To be specific, 'Object' is a function in turn it is an object since functions are first-class object in javascript. 具体来说,“对象”是一个函数,而它又是一个对象,因为函数是javascript中的一类对象。

If you want to check the source code of built-ins, below is the V8 engine open-source repository in Github. 如果要检查内置源代码,请参阅以下Github中的V8引擎开源存储库。

https://github.com/v8/v8/blob/master/src/builtins/builtins-object.cc https://github.com/v8/v8/blob/master/src/builtins/builtins-object.cc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM