關於JavaScript中[native code]


關於JavaScript中[native code]

一、總結

一句話總結:

1、[native code] 意思已經很明確了:是 native 的代碼實現的 built-in 函數,而不是 JavaScript 代碼
2、An implementation-dependent representation of the function is returned.

 

 

 

二、關於JavaScript中[native code]

轉自或參考:

 

 

 

[native code] 意思已經很明確了:是 native 的代碼實現的 built-in 函數,而不是 JavaScript 代碼。

但這並不是語言標准規定的。只是恰好 Firefox、Chrome 都這么干而已。

語言標准里有說:

15.2.4.2 Function.prototype.toString()


An implementation-dependent representation of the function is returned.

它是 implementation-dependent 的。

說到 V8,可以看 v8natives.js 第 1710 行附近的 FunctionSourceString 函數:
return 'function () { [native code] }'; 
這就是 V8 是怎么返回 [native code] 這一串字符串的。



 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM