Last active
February 2, 2018 02:19
-
-
Save nmaxcom/6185503fcfa0732031299cd31d716091 to your computer and use it in GitHub Desktop.
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
-- Human.js ----------------------------------------------------- | |
const Human = () => ({ | |
name:'', | |
health: 100, | |
energy: 100, | |
hunger: 0, | |
age: 30, | |
changeProp: function(pair) { | |
this[Object.keys(pair)[0]] = Object.values(pair)[0]; | |
}, | |
getProp: function(key) { | |
return this[key]; | |
}, | |
}); | |
module.exports = Human; | |
-- Scientist.js ----------------------------------------------------- | |
const Human = require('./Human'); | |
const maxAge = 60, minAge = 19; | |
const scientist = name => { | |
let obj = Object.assign({}, Human()); | |
obj.changeProp({"age": Math.round(Math.random() * (maxAge - minAge) + minAge)}); | |
obj.name = name; | |
let scienceObj = { | |
experience: 'skin cancer', | |
carrying: 'cellphone', | |
talk: function() { | |
console.log(`Well, my mane is ${this.name}, I'm ${this.age} years old and I know about ${this.experience}${this.carrying ? `. And I'm carry my ${this.carrying}` :'' }`); | |
}, | |
}; | |
return Object.assign({}, obj, scienceObj); | |
}; | |
module.exports = scientist; | |
-- main.js ----------------------------------------------------- | |
const scientist = require("./scientist"); | |
const Joe = scientist('Joe Mazzini'); | |
Joe.talk(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment