Created
April 2, 2018 06:52
-
-
Save vampaynani/8a083c91f2e38d75ef467845d19b6c1a to your computer and use it in GitHub Desktop.
Constructor, Instance, Composition
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*============== | |
* Constructor | |
===============*/ | |
/* function Kitty: | |
* prototype: Function | |
* __proto__: Object | |
*/ | |
function Kitty(){ | |
this.legs = 4; | |
this.eyes = 2; | |
} | |
Kitty.prototype.lifes = 7; | |
Kitty.prototype.ears = 2; | |
/*============== | |
* Instance | |
===============*/ | |
/* misifus: | |
* prototype: Kitty | |
*__proto__: Object | |
*/ | |
let misifus = new Kitty(); | |
/*============== | |
* Composition | |
===============*/ | |
const food = name => ({food: name}); | |
const box = hasOne => ({box: hasOne}); | |
const feed = () => { | |
return { | |
feed: function(){ | |
console.log(`Mhhh, ${this.food}`); | |
} | |
} | |
} | |
/* garfield: | |
* prototype: Kitty | |
*__proto__: Object | |
*/ | |
let garfield = Object.assign(new Kitty(), food('lasagna'), box(true), feed()); | |
garfield.feed(); | |
console.log(garfield) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment