簡體   English   中英

在JavaScript中,函數的prototype屬性的默認值是什么?

[英]In JavaScript, what is the default value of a function's prototype property?

在Chrome的JavaScript控制台中:

function placeOrder() {
        return 1;
};
undefined
console.log(placeOrder.prototype);
placeOrder {}

但在IE 11中,默認的prototype屬性似乎是一個空對象。 我想知道Chrome中的對象“placeOrder {}”是什么? 我也在Firefox中測試過它。 在Firefox中,prototype屬性也是“placeOrder {}”。

在IE 11控制台中:

function placeOrder() {
        return 1;
};
undefined
console.log(placeOrder.prototype);
undefined
[object Object]{} 

謝謝。

它是一個繼承自Object.prototype的對象,它有一個自己的constructor屬性,其值是構造函數。

請參見創建函數對象

  1. proto成為創建一個新對象的結果,該對象將由表達式new Object()構造,其中Object是具有該名稱的標准內置構造函數。
  2. 使用參數"constructor"調用proto的[[DefineOwnProperty]]內部方法, 屬性描述符 {[[Value]]: F ,{[[Writable]]: true ,[[Enumerable]]: false ,[[Configurable]] : true }, false
  3. 使用參數"prototype"調用F的[[DefineOwnProperty]]內部方法, 屬性描述符 {[[Value]]: proto ,{[[Writable]]: true ,[[Enumerable]]: false ,[[Configurable]] : false }, false

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM