So, I have this code:
var exampleModule = (function() {
var example = {};
var self = this;
example.test = function() {
this.mousedown = function (e) {
self.x1 = e.offsetX;
self.y1 = e.offsetY;
};
this.mousemove = function(e) {
// do something with x1 and y1 and e.offsetX and e.offsetY
};
};
})();
I'd like to have x1
and y1
only be scoped within example.test. Is there any way to do this with this
or do I have to do something like example.test.x1
for each one? Currently they are scoped to the entire exampleModule
and I would like to narrow this to just example.test
.
I only somewhat understand the whole self/that = this;
mantra. I know that Javascript has this bug where this
when in a function in a function refers to the global scope instead, but what of when there are 3 functions like in the example above? What is this
equal to when nested three or four functions down?