function(){
"use strict";
var FileCrop = function() {
this.init();
};
var p = FileCrop.prototype = lx.BaseClass.extend(lx.BaseClass);
p.BaseClass_init = p.init;
p.test = 'test';
p.init = function() {
// Super
this.BaseClass_init();
// Init
this.ready();
};
p.ready = function() {
this._initEvents();
};
p._initEvents = function() {
console.log(this.test); //this works
this.cropBox.on('mousedown', this.mouseDown);
$(document).on('mouseup', this.mouseUp);
};
p.mouseDown = function(e) {
console.log(this.test);//this is undefined
$(document).on('mousemove', this.mouseMove);
};
p.mouseMove = function(e) {
console.log('mouse is moving'); //this is never called
};
lx.FileCrop = FileCrop;
}(window));
I'm having trouble with scope and my class.
It would be great if someone could explain to me what I'm doing wrong. I'm trying to get the test variable throughout the class (in the real class its something else but this gives an easy to understand example).
I have commented on the code above where the test var logs ok and where it doesn't. I'm also having trouble with mouse move. This fails:
$(document).on('mousemove', this.mouseMove);
Whereas this works:
$(document).on('mousemove', p.mouseMove);
I was just wondering why this is the case as I am able to use 'this' on mouse down and it works.