重慶分公司,新征程啟航
為企業提供網站建設、域名注冊、服務器等服務
為企業提供網站建設、域名注冊、服務器等服務
prototype與__proto__區別
Each constructor is a function that has a property named “prototype” that is used to implement prototype-based inheritance and shared properties. Every object created by a constructor has an implicit reference (called the object's prototype) to the value of its constructor's “prototype” property.
When a constructor creates an object, that object implicitly references the constructor's prototype property for the purpose of resolving property references. The constructor's prototype property can be referenced by the program expression constructor.prototype, and properties added to an object's prototype are shared, through inheritance, by all objects sharing the prototype. Alternatively, a new object may be created with an explicitly specified prototype by using the Object.create built-in function. –ECMAScript® 2015 Language Specification
__proto__是每個對象都有的一個屬性,而prototype是函數才會有的屬性!!!
使用Object.getPrototypeOf()代替__proto__!!!
一、prototype
幾乎所有的函數(除了一些內建函數)都有一個名為prototype(原型)的屬性,這個屬性是一個指針,指向一個對象,而這個對象的用途是包含可以有特定類型的所有實例共享的屬性和方法。prototype是通過調用構造函數而創建的那個對象實例的原型對象。hasOwnProperty()判斷指定屬性是否為自有屬性;in操作符對原型屬性和自有屬性都返回true。
示例:自有屬性&原型屬性
var obj = {a: 1}; obj.hasOwnProperty("a"); // true obj.hasOwnProperty("toString"); // false "a" in obj; // true "toString" in obj; // true
另外有需要云服務器可以了解下創新互聯建站www.cdcxhl.com,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業上云的綜合解決方案,具有“安全穩定、簡單易用、服務可用性高、性價比高”等特點與優勢,專為企業上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。