Skip to content

Instantly share code, notes, and snippets.

@howarddierking
Created September 11, 2018 22:18
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 howarddierking/0919f9a5384ccb288728386cfc0ab30c to your computer and use it in GitHub Desktop.
Save howarddierking/0919f9a5384ccb288728386cfc0ab30c to your computer and use it in GitHub Desktop.
// This succesfully merges the supplied object with the state object
function builder(){
let state = {};
return {
options: function (){
state = mergeFragment('opts', state, optionsFragment(...arguments));
},
product: function(){
return state;
}
}
}
// Instead of correctly updating state, this sets its value to `Function f1`
function builder(){
let state = {};
return {
options: () => {
state = mergeFragment('opts', state, optionsFragment(...arguments));
},
product: () => {
return state;
}
}
}
@jdubray
Copy link

jdubray commented Sep 11, 2018

Have you considered that Arrow functions do not have their own arguments object. so in the second case, arguments will reference the arguments of the enclosing scope (not sure what you mean by function f1), I would expect it references arguments of the builder function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment