Merge Dynamic Objects with Global Objects
In this exercise we'll work with globals.
Here's an addAllOfThisToWindow
object:
const addAllOfThisToWindow = {
add: (a: number, b: number) => a + b,
subtract: (a: number, b: number) => a - b,
multiply: (a: number, b: number) => a * b,
divide: (a: number, b: number) => a /
Transcript
0:00 This challenge relates to globals. We're trying to do something interesting. We have an addAllOfThisToWindow object, where we're basically taking add, subtract, multiply, and divide. We're trying to add them all to the window.
0:15 We could do this with like, "declare global interface Window" and add all of them manually. We could say, "add" is "typeof addAllOfThisToWindow.add," for instance, but this is going to get pretty tiresome, pretty quickly. We do see that this does work. Like window.add, basically, when it's added to the window, then these tests will start passing.
0:39 It would be great if we could find a way of doing this where we didn't have to add all of them individually. We could just say take all of this and then just merge it in with the global window. That's your challenge. Somehow, you need to find a way of doing this declare global where you basically add that stuff into the window. Good luck.