Calling function from an object with event listener
Posted
by
Mirat Can Bayrak
on Stack Overflow
See other posts from Stack Overflow
or by Mirat Can Bayrak
Published on 2012-06-16T20:58:53Z
Indexed on
2012/06/16
21:16 UTC
Read the original article
Hit count: 141
JavaScript
|javascript-events
i have a view model something like this:
CANVAS = getElementById...
RemixView = function(attrs) {
this.model = attrs.model;
this.dragging = false;
this.init();
};
RemixView.prototype = {
init: function() {
CANVAS.addEventListener("click", this.handleClick);
},
handleClick: function(ev) {
var obj = this.getHoveredObject(ev);
},
getHoveredObject: function(ev) {}
...
...
}
rv = new RemixView()
the problem is my when clickHandler event fired, this object is being equal to CANVAS object, not RemixView. So i get error that says:
this.getHoveredObject is not a function
What is correct approach at that stuation?
© Stack Overflow or respective owner