Associate
- Joined
- 11 Oct 2008
- Posts
- 268
Hey guys. Happy new year!
I'm slowly getting my head around javascript, with a lot of help from this forum
I am using this code to listen out for touches which is working well now.
It seems like I am repeating myself quite a lot. Is there a better technique I could be using for the following?
Thanks
I'm slowly getting my head around javascript, with a lot of help from this forum

I am using this code to listen out for touches which is working well now.
It seems like I am repeating myself quite a lot. Is there a better technique I could be using for the following?
Code:
function onload(){
var left= document.getElementById('left')
left.addEventListener('touchstart', function (){ move('left') }, false);
left.addEventListener('touchend', function (){ move('left') }, false);
var right= document.getElementById('right')
right.addEventListener('touchstart', function (){ move('right') }, false);
right.addEventListener('touchend', function (){ move('right') }, false);
var up= document.getElementById('up')
up.addEventListener('touchstart', function (){ move('up') }, false);
up.addEventListener('touchend', function (){ move('up') }, false);
var down= document.getElementById('down')
down.addEventListener('touchstart', function (){ move('down') }, false);
down.addEventListener('touchend', function (){ move('down') }, false);
}
Thanks
