How to make object move in js?
问题 I'm trying to learn object oriented programming in javascript so I try to make a simple game. I would like to make a character that moves. There is the code in js: function move(event) { var k=event.keyCode; var chr = { updown : function (){ var y=0; if (k==38) {--y; }else if (k==40) {++y;} return y; }, leftright : function (){ var x=0; if (k==37) {--x; }else if (k==39) {++x;} return x; } }; chrId.style.top = (chr.updown())+"px"; chrId.style.left = (chr.leftright())+"px"; } html: <!DOCTYPE