Let's simplify this by focusing on the problem code only:
var object; // undefined
object.rotation.x += 0.1; // attempting to access a key in an undefined object
While declaring object
in the global scope is permissible, it's crucial to note that you're simply declaring it without assigning a value. This results in an attempt to access a key within an object that is undefined
.
var object = {};
object.rotation.x += 0.1; // object.rotation is undefined
This approach is still insufficient. The variable object
lacks a key called rotation
, leading to it being undefined. Consequently, you're trying to access a key that does not exist. While I'm uncertain about your specific requirement, in this particular case, assigning object
as an object with all the necessary keys manually can resolve the undefined
issue you're facing.
var object = {
rotation: {
x: 0
}
};
object.rotation.x += 0.1;