Upcoming SlideShare
×

# Demystifying Prototypes

12,805 views

Published on

1 Comment
25 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Thank you for god presentation.

Are you sure you want to  Yes  No
Views
Total views
12,805
On SlideShare
0
From Embeds
0
Number of Embeds
415
Actions
Shares
0
166
1
Likes
25
Embeds 0
No embeds

No notes for slide

### Demystifying Prototypes

1. 1. Demystifying Proto........... types
2. 2. types
3. 3. null undeﬁned numberstring boolean object
4. 4. null undeﬁned numberstring boolean object
5. 5. b.name b[“name”] “a” in b for (var i in b) …b.hasOwnProperty(“a”) b instanceof d
6. 6. functionfunction f() {};f();new f;
7. 7. functionfunction f() {};f();new f;
8. 8. functionfunction f() {};f();new f;
9. 9. ObjectNumberStringBooleanFunctionArrayRegExpDate
10. 10. Afunction A() {};
11. 11. constructor: A Afunction A() {};
12. 12. constructor: A A bfunction A() {};var b = new A;
13. 13. constructor: A A x: 1 bfunction A() {};var b = new A;A.prototype.x = 1;
14. 14. constructor: A A x: 1 b y: 2function A() {};var b = new A;A.prototype.x = 1;b.y = 2;
15. 15. constructor: A A x: 1 c b y: 2function A() {};var b = new A;A.prototype.x = 1;b.y = 2;var c = new A;
16. 16. constructor: A A x: 1 c b y: 2function A() {};var b = new A;A.prototype.x = 1;b.y = 2;var c = new A;A.prototype = {v: 1, w: 2};
17. 17. v: 1 constructor: Aw: 2 A x: 1 c b y: 2 function A() {}; var b = new A; A.prototype.x = 1; b.y = 2; var c = new A; A.prototype = {v: 1, w: 2};
18. 18. v: 1 constructor: Aw: 2 A x: 1 d c b y: 2 function A() {}; var b = new A; A.prototype.x = 1; b.y = 2; var c = new A; A.prototype = {v: 1, w: 2}; var d = new A;
19. 19. v: 1 constructor: A w: 2 A P x: 1 d c b y: 2P.hasOwnProperty(“constructor”)“constructor” in cfor (var i in P) alert(i);c.constructorc instanceof Ad instanceof Ad.constructor
20. 20. null Object Ac d
21. 21. null Objectfunction A() {};function B() {};B.prototype = new A; Avar d = new B; B d
22. 22. null Objectfunction A() {…};function B() {};var Z = function () {}; AZ.prototype = A.prototype;B.prototype = new Z;var d = new B; B d
23. 23. null Objectfunction A() {…};function B() {};var Z = function () {}; AZ.prototype = A.prototype;B.prototype = new Z; Zvar d = new B; B d
24. 24. goog.inherits = function(childCtor, parentCtor) { /** @constructor */ function tempCtor() {}; tempCtor.prototype = parentCtor.prototype; childCtor.superClass_ = parentCtor.prototype; childCtor.prototype = new tempCtor(); childCtor.prototype.constructor = childCtor;};
25. 25. exports.inherits = function(ctor, superCtor) { ctor.super_ = superCtor; ctor.prototype = Object.create(superCtor.prototype, { constructor: { value: ctor, enumerable: false } });};
26. 26. null Object FunctionA
27. 27. null Object FunctionA
28. 28. JavaScript ParadoxFunction.constructor === Function
29. 29. Thank Youdmitry@baranovskiy.com