Assigning a function to an object only is not related to this inside a function with an object. So you call the function.
Causing
.hover(my_zoomin.hoverOn,...)
you pass the function only. He will not βrememberβ to which object he belonged. What you can do is pass an anonymous function and call hoverOn inside:
.hover(function(){ my_zoomin.hoverOn(); },...)
This will make this inside hoverOn reference to my_zoomin . So calling this.hoverReset() will work. However, inside hoverOn you will not have a reference to the jQuery object created by the selector.
One solution would be to pass the selected items as a parameter:
var zoomin = function() { // Constructor goes here }; zoomin.prototype = { hoverOn: function($ele) { this.hoverReset($ele); // More logic here using jQuery $ele... }, hoverReset: function($ele) { // Some logic here. } }; var my_zoomin = new zoomin(); $(".some_class").hover(function() { my_zoomin.hoverOn($(this)); // pass $(this) to the method }, function() { return null; });
As a next step, you might consider creating a jQuery plugin .
source share