How To Solve The Jshint Error `don't Make Functions Within A Loop.` With Jquery $.grep
The following javascript code gives me the Don't make functions within a loop. error /* Get the favorite products from the data using the id */ productDataCategory[FAVORITES].lengt
Solution 1:
Put the function outside the loop:
/* Get the favorite products from the data using the id */
productDataCategory[FAVORITES].length = 0/* empty favorites productDataCategory */;
var f = function(e){ return e.id === currentUser.favorites[i]; };
for ( i = 0; i < currentUser.favorites.length; i++) {
product = $.grep(productData, f)[0];
productDataCategory[FAVORITES].push(p);
}
Post a Comment for "How To Solve The Jshint Error `don't Make Functions Within A Loop.` With Jquery $.grep"