Skip to content
Advertisement

Cannot Read Property ‘update’ of undefined

The Chest Objects i’ve created have an update function, but apparently they dont exist or are not declared?

I feel like ive been pretty thourough checking my work, but it’s pretty complicated and possibly above me and have no idea whats wrong, my code is commented so as to make your job easier since I do not have much help to give

JavaScript

Any help is -Greatly- appreciated since im just a highschooler who is just trying to learn how to do great things with code thumbs up

Expected – 4 Chests should appear, with their inventory slots above them, 4 slots -More chests should be easily addable, and more slots should be able to be added to each chest at will Actual- 4 Slots from the player (still broken but not the current problem) object appear, then it breaks saying ‘update’ is not defined)

Advertisement

Answer

Try changing

JavaScript

to

JavaScript

The new keyword is important in properly constructing an object with the correct context. It also properly returns a Chest object to be pushed to your array.

You can find more information with this Stackoverflow answer: https://stackoverflow.com/a/30478240/11240618, as well as here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement