Last active
September 26, 2016 14:24
-
-
Save vsakaria/cb8be82a7171220b95e3a70cf5a5dbb2 to your computer and use it in GitHub Desktop.
Demonstrating my understanding of call and apply
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ComparisonTable = (function ($) { | |
var init = function () { | |
$("td, th").on('mouseenter',function() { | |
var col = $(this).parent().children().index($(this)); | |
$('.eh-column').each(function () { | |
$(this).removeClass(); | |
}); | |
$('#column-' col).attr('class', 'column-boarder'); | |
}); | |
$("td, th").on('mouseleave',function() { | |
var col = $(this).parent().children().index($(this)); | |
$('.eh-column').each(function () { | |
$(this).removeClass(); | |
}); | |
$('#column-' col).attr('class', 'table-compare-products-v2'); | |
}); | |
}; | |
return { | |
init: init | |
}; | |
})(jQuery); | |
/////////////ANSWER///////////////////////////////////////////////////////////////////////// | |
var ComparisonTable = (function ($) { | |
var init = function () { | |
$("td, th").on('mouseenter',function() { | |
var col = getColumn.call(this); | |
handleStyling.call(this); | |
$('#column-' col).attr('class', 'column-boarder'); | |
}); | |
$("td, th").on('mouseleave',function() { | |
var col = getColumn.call(this); | |
handleStyling.call(this); | |
$('#column-' col).attr('class', 'table-compare-products-v2'); | |
}); | |
}; | |
var handleStyling = function () { | |
$('.eh-column').each(function () { | |
$(this).removeClass(); | |
}); | |
}; | |
var getColumn = function () { | |
return $(this).parent().children().index($(this)); | |
}; | |
return { | |
init: init | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment