Bonsoir tout le monde,
J'essaye d'apprendre à faire du js en objet mais là ça coince et je ne comprend vraiment pas pourquoi...
C'est une classe qui récupère les coordonnées de la souris, et la console Firefox renvoie une erreur : "this.getPos is not a function" dans la fonction init();
Le code :J'ai tenté avec un namespace mais c'est pareil :( :Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 var Tracking = { xy : [], allpos : [], event : null, init : function(e) { this.event = (!e) ? window.event : e; this.getPos(); }, getPos : function() { if (this.event.pageX || this.event.pageY) { this.xy = [e.pageX, e.pageY]; } else if (this.event.clientX || this.event.clientY) { this.xy = [ e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft, e.clientY + document.body.scrollTop + document.documentElement.scrollTop ]; } this.addPos(); alert(this.xy[0]+'-'+this.xy[1]); }, addPos : function() { this.allpos.push(this.xy); } };
Et c'est initialisé comme ça :Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 var Tracking = function() { var xy, allpos, event; function getPos() { if (this.event.pageX || this.event.pageY) { this.xy = [e.pageX, e.pageY]; } else if (this.event.clientX || this.event.clientY) { this.xy = [ e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft, e.clientY + document.body.scrollTop + document.documentElement.scrollTop ]; } this.addPos(); alert(this.xy[0]+'-'+this.xy[1]); } function addPos() { this.allpos.push(this.xy); } return { init : function(e) { this.xy = []; this.allpos = []; this.event = (typeof(e) == 'undefined') ? window.event : e; this.getPos(); } }; }();
Voyez-vous d'où ça peut venir ?Code:addEvent(window.document, 'mousemove', Tracking.init);
Merci d'avance pour votre aide !