demystifying prototypes

Download Demystifying Prototypes

Post on 15-May-2015

10.638 views

Category:

Technology

1 download

Embed Size (px)

TRANSCRIPT

  • 1. Demystifying Proto...........types

2. types 3. null undened numberstring booleanobject 4. null undened numberstring booleanobject 5. b.name b[name] a in bfor (var i in b) b.hasOwnProperty(a) b instanceof d 6. functionfunction f() {};f();new f; 7. functionfunction f() {};f();new f; 8. functionfunction f() {};f();new f; 9. ObjectNumberStringBooleanFunctionArrayRegExpDate 10. Afunction A() {}; 11. constructor: A Afunction A() {}; 12. constructor: A Abfunction A() {};var b = new A; 13. constructor: A A x: 1 bfunction A() {};var b = new A;A.prototype.x = 1; 14. constructor: A A x: 1 b y: 2function A() {};var b = new A;A.prototype.x = 1;b.y = 2; 15. constructor: A A x: 1cb y: 2function A() {};var b = new A;A.prototype.x = 1;b.y = 2;var c = new A; 16. constructor: AA x: 1cby: 2function A() {};var b = new A;A.prototype.x = 1;b.y = 2;var c = new A;A.prototype = {v: 1, w: 2}; 17. v: 1 constructor: Aw: 2 A x: 1 cby: 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. v: 1 constructor: Aw: 2 A x: 1 d cby: 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. v: 1constructor: Aw: 2 A Px: 1 d c by: 2P.hasOwnProperty(constructor)constructor in cfor (var i in P) alert(i);c.constructorc instanceof Ad instanceof Ad.constructor 20. null ObjectAc d 21. nullObjectfunction A() {};function B() {};B.prototype = new A; Avar d = new B; B d 22. nullObjectfunction A() {};function B() {};var Z = function () {}; AZ.prototype = A.prototype;B.prototype = new Z;var d = new B; B d 23. nullObjectfunction A() {};function B() {};var Z = function () {}; AZ.prototype = A.prototype;B.prototype = new Z; Zvar d = new B; B d 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. exports.inherits = function(ctor, superCtor) { ctor.super_ = superCtor; ctor.prototype = Object.create(superCtor.prototype, { constructor: { value: ctor, enumerable: false } });}; 26. nullObject FunctionA 27. nullObject FunctionA 28. JavaScript ParadoxFunction.constructor === Function 29. Thank Youdmitry@baranovskiy.com