Skip to content

Instantly share code, notes, and snippets.

@davelosert
Last active November 7, 2017 11:28
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 davelosert/225c4ab4fac88747754dae1306453e4e to your computer and use it in GitHub Desktop.
Save davelosert/225c4ab4fac88747754dae1306453e4e to your computer and use it in GitHub Desktop.
Object Spread and Classes don't mix
class MyClass {
greet: () => console.log('Hello World')
}
const myObject = {
...new MyClass()
}
// will throw "myObject.greet" is not a function as the greeting is on the prototype, not the acutal instantiated class object
myObject.greet()
const createMyClass = () => ({
greet: () => console.log('Hello World');
});
const myObject = {
...createMyClass()
}
// will log "Hello World"
myObject.greet()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment