Last active
November 7, 2017 11:28
-
-
Save davelosert/225c4ab4fac88747754dae1306453e4e to your computer and use it in GitHub Desktop.
Object Spread and Classes don't mix
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
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() |
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
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