Created
September 16, 2016 17:53
-
-
Save alexortiz201/87d1ec5d6ee92a8f0862950a9813a363 to your computer and use it in GitHub Desktop.
Simple object factory
This file contains 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
let module = { | |
create: function(greeting, name) { | |
/** | |
* Ran into issue with lexical scoping when | |
* using the fat arrow. Wanted to make a note | |
* here. | |
**/ | |
const obj = { | |
sayIt: function () { | |
console.log(this); | |
return `${this.greeting} ${this.name}`; | |
}, | |
}; | |
return Object.assign({}, obj, { | |
name, | |
greeting, | |
}); | |
} | |
}; | |
alex = module.create('hello', 'alex'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment