
November 29th, 2012, 12:01 PM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 2
Time spent in forums: 8 m 8 sec
Reputation Power: 0
|
|
Singleton and Window eventlisteners
Hi there .. im trying to add an eventlistener to my singleton pattern, so i can get the mouse position .. for some reason the event in function(event) isnt being caught .. can anyone help me?
here's the basic code
Code:
var App = {};
App = function(){
this.mouse;
this.SCREEN_WIDTH = 100;
this.SCREEN_HEIGHT = 100;
this.init();
}
App.prototype = {
init:function(){
var me = this;
window.addEventListener( 'mousemove', function(e){
this.mouse = {x: e.clientX - this.SCREEN_WIDTH/2, y: e.clientY - this.SCREEN_HEIGHT/2};
me.render();
});
},
render:function(){
console.log(this.mouse.x);
}
}
var prog = new App();

|