Skip to content

Instantly share code, notes, and snippets.

@alexortiz201
Created September 16, 2016 17:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexortiz201/87d1ec5d6ee92a8f0862950a9813a363 to your computer and use it in GitHub Desktop.
Save alexortiz201/87d1ec5d6ee92a8f0862950a9813a363 to your computer and use it in GitHub Desktop.
Simple object factory
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