Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var addChainableMandP = function (pr) {
- for (var prop in pr) {
- if (!pr.hasOwnProperty(prop)) {
- continue;
- }
- this[prop] = pr[prop];
- }
- return this;
- };
- var CreateChainableObject = function() {
- this.constructorPropertyOne = 'Constructor Property One';
- this.constructorPropertyTwo = 'Constructor Property Two';
- this.addMandP = addChainableMandP;
- };
- CreateChainableObject.prototype.prototypePropertyOne = 'Prototype Property One';
- CreateChainableObject.prototype.prototypePropertyTwo = 'Prototype Property Two';
- CreateChainableObject.prototype.prototypeMethod = function () {
- console.log('Prototype Method');
- return this;
- };
- var initObject = new CreateChainableObject();
- initObject
- // Calling method on prototype
- .prototypeMethod()
- // Decorating object
- .addMandP({objectLogMethod: function (arg1) {console.log(arg1); return this;}})
- // Listing properties on object
- .objectLogMethod(initObject.constructorPropertyOne)
- .objectLogMethod(initObject.constructorPropertyTwo)
- // Listing properties on prototype
- .objectLogMethod(initObject.prototypePropertyOne)
- .objectLogMethod(initObject.prototypePropertyTwo)
- // Additional decorating on object
- .addMandP({constructorDecoration: 'Constructor Decoration'})
- // Listing decorations
- .objectLogMethod(initObject.constructorDecoration)
- // Overriding property on object
- .addMandP({constructorPropertyOne: 'Constructor Property One - Overriden'})
- // Listing new properites
- .objectLogMethod(initObject.constructorPropertyOne)
- ;
- Prototype Method
- Constructor Property One
- Constructor Property Two
- Prototype Property One
- Prototype Property Two
- Constructor Decoration
- Constructor Property One - Overriden
- CreateChainableObject.prototype.addProtoMandP = addChainableMandP;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement