Add optional data parameter to each function
by Akram kamal
HTML
<div>
</div>
<div>
</div>
JavaScript
jQuery.fn.eachP = function(f) {
var extras = Array.prototype.slice.call(arguments, 1);
console.log("extras", extras);
return this.each(function() {
var args = Array.prototype.slice.call(arguments).concat(extras);
f.apply(this, args);
})
}
var myData = [1, 2, 3];
$(function() {
$("div").eachP(myHighlightFunction, myData);
})
function myHighlightFunction() {
console.log(arguments);
}