Successfully reported this slideshow.

Prototypes and inheritance in javascript

590 views

Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Prototypes and inheritance in javascript

  1. 1. drake
  2. 2.  What is prototype ?
  3. 3. Wikipedia Say: …樣品 (prototype) 是指某種新技術在投入量產之前的所作的模型,用以檢測產品質量,保障正常運行。在電子技術、機械工程、車輛工程等方面廣泛運用,實驗產品相應地被稱為樣機,樣車等。
  4. 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. 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);
  6. 6. What Makes PrototypesSpecial?
  7. 7. Example
  8. 8. Sharing Prototypes
  9. 9. Example
  10. 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. 11.  Imagine we want to create a new object and make the new object behave like an array
  12. 12. 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.
  13. 13. Reference http://msdn.microsoft.com/en-us/magazine/ff852808.aspx

×