Javascript 對象的解釋

來源:互聯網
上載者:User

所有的構造器都是對象,而並非所有的對象都是構造器.每個構造器都有一個用來實現原型繼承、共用屬性的Prototype屬性。對象通過new 運算式建立;比如,new String("A String") 建立了一個String對象。沒有通過new而直接調用構造器將有傳回值,返回的類型將取決於構造器。例如String("A String")產生一個原始的類型的字串而不是一個對象。
ECMAScript支援基於原型的繼承。每個構造器都有一個與之關聯的原型,而且通過此構造器建立的對象都有一個與構造器原型關聯的隱式引用(稱為,對象的原型)。進一步說,一個原型可能有一個對其原型的非空隱式引用……,這被稱為,原型鏈。當一個引用指向對象的屬性,這個引用指向原型鏈中的第一個對象的以此為名的屬性。換句話說,第一次,這個直接關聯的對象,將為這個屬性被檢查。如果這個對象包含以此為名的屬性,這個屬性就是引用指向的屬性。如過這個對象不包含以此為名的屬性,那麼這個對象的原型將會被繼續檢查……
原文:
Object
ECMAScript does not contain proper classes such as those in C++, Smalltalk, or Java, but rather,supports constructors which create objects by executing code that allocates storage for the objects and initialises all or part of them by assigning initial values to their properties. All constructors are objects,but not all objects are constructors. Each constructor has a Prototype property that is used to implement prototype-based inheritance and shared properties. Objects are created by using constructors in new expressions; for example, new String("A String") creates a new String object. Invoking a constructor without using new has consequences that depend on the constructor. For example,String("A String") produces a primitive string, not an object.
ECMAScript supports prototype-based inheritance. Every constructor has an associated prototype, and every object created by that constructor has an implicit reference to the prototype (called the object's prototype) associated with its constructor. Furthermore, a prototype may have a non-null implicit reference to its prototype, and so on; this is called the prototype chain. When a reference is made to a property in an object, that reference is to the property of that name in the first object in the prototype chain that contains a property of that name. In other words, first the object mentioned directly is examined for such a property; if that object contains the named property, that is the property to which the reference refers; if that object does not contain the named property, the prototype for that object is examined next; and so on.
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.