3. Wikipedia Say: …
樣品 (prototype) 是指某種新技術在投入量產之前的所
作的模型,用以檢測產品質量,保障正常運行。在電子
技術、機械工程、車輛工程等方面廣泛運用,實驗產品
相應地被稱為樣機,樣車等。
4. Of Objects and Classes
JavaScript is full of objects
Ex: Array in JavaScript is an object with values and also
methods like push, reverse, and pop
Where does a method like push come from?
5. Of Prototypes
Every object in JavaScript holds a hidden piece of
state __proto__
How can we grab that reference ?
Object.getPrototypeOf(point) != Object.getPrototypeOf(myArray);
10. Of Functions
Functions in JavaScript are objects
Every function object in JavaScript has a prototype
property
Do not confuse this prototype property with the
__proto__ property – they do not serve the same
purpose or point to the same object.
11.
12. Imagine we want to create a new object and make the
new object behave like an array
13. Constructor Functions
The first letter of a constructor function is
capitalized by convention
A constructor function expects to be used in
conjunction with the new operator to construct
objects.
1. JavaScript is a classless language and there is no Array “class” defining the methods for every array object. 2. JavaScript is dynamic, we can arbitrarily place methods into an object on an as-needed basis.
1. a reference to another object known as the object’s prototype
The new operator in JavaScript has three essential tasks. First, it creates a new empty object. Next, it sets the new object’s __proto__ property to match the prototype property of the function being invoked. Finally, the operator invokes the function and passes the new object as the “this” reference. The call method of a function allows you to invoke a function and specify the object to use as the “this” reference inside the function.