Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. var addChainableMandP = function (pr) {
  2. for (var prop in pr) {
  3. if (!pr.hasOwnProperty(prop)) {
  4. continue;
  5. }
  6. this[prop] = pr[prop];
  7. }
  8. return this;
  9. };
  10.  
  11. var CreateChainableObject = function() {
  12. this.constructorPropertyOne = 'Constructor Property One';
  13. this.constructorPropertyTwo = 'Constructor Property Two';
  14. this.addMandP = addChainableMandP;
  15. };
  16.  
  17. CreateChainableObject.prototype.prototypePropertyOne = 'Prototype Property One';
  18. CreateChainableObject.prototype.prototypePropertyTwo = 'Prototype Property Two';
  19. CreateChainableObject.prototype.prototypeMethod = function () {
  20. console.log('Prototype Method');
  21. return this;
  22. };
  23.  
  24. var initObject = new CreateChainableObject();
  25.  
  26. initObject
  27. // Calling method on prototype
  28. .prototypeMethod()
  29. // Decorating object
  30. .addMandP({objectLogMethod: function (arg1) {console.log(arg1); return this;}})
  31. // Listing properties on object
  32. .objectLogMethod(initObject.constructorPropertyOne)
  33. .objectLogMethod(initObject.constructorPropertyTwo)
  34. // Listing properties on prototype
  35. .objectLogMethod(initObject.prototypePropertyOne)
  36. .objectLogMethod(initObject.prototypePropertyTwo)
  37. // Additional decorating on object
  38. .addMandP({constructorDecoration: 'Constructor Decoration'})
  39. // Listing decorations
  40. .objectLogMethod(initObject.constructorDecoration)
  41. // Overriding property on object
  42. .addMandP({constructorPropertyOne: 'Constructor Property One - Overriden'})
  43. // Listing new properites
  44. .objectLogMethod(initObject.constructorPropertyOne)
  45. ;
  46.  
  47. Prototype Method
  48. Constructor Property One
  49. Constructor Property Two
  50. Prototype Property One
  51. Prototype Property Two
  52. Constructor Decoration
  53. Constructor Property One - Overriden
  54.  
  55. CreateChainableObject.prototype.addProtoMandP = addChainableMandP;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement