Skip to content

Instantly share code, notes, and snippets.

Created August 17, 2017 01:50
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 anonymous/422eab1c41d7ac550590c6da4750aaa8 to your computer and use it in GitHub Desktop.
Save anonymous/422eab1c41d7ac550590c6da4750aaa8 to your computer and use it in GitHub Desktop.
const defaults = (obj, defaultProps) => {
Object.keys(obj).forEach((key) => {
if (obj[key] === undefined) obj[key] = defaultProps[key];
});
};
const Foo = function() {
const instance = {};
defaults(instance, instanceMethods);
instance.value = 0;
return instance;
};
const instanceMethods = {
bar: () => {
instance.value++;
}
};
const f = new Foo();
f.bar() // outputs "ReferenceError: instance is not defined [Learn More]". why?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment