JavaScript Avoid defining a function in a loop when using an IIFE

I have the following following code:

for (i = 0; i < 5; i++) {
    this.hands[0].cards[i].img.on('mousedown', (function (i) {
        var j = i;
        return function (event) {
            self.hands[0].cards[j].holdCard();
        };
    })(i));
}

This is working fine for my needs but JSHint is complaining:

[L1164:C10] W083: Don't make functions within a loop.

How can I keep JSHint happy by rewriting this differently?

Answer:1

I am writing in Casper Javacript and I am writing a test for a search bar object that tests each letter of the alphabet, by itself. So it will test 'a' then 'b' and so on. I am using the sendKeys ...

I am writing in Casper Javacript and I am writing a test for a search bar object that tests each letter of the alphabet, by itself. So it will test 'a' then 'b' and so on. I am using the sendKeys ...

  1. reset search field jquery
  2. datatables reset search field

My HTML: <div id="listViewBoxOffice" data-win-control="WinJS.UI.ListView" data-win-options="{ itemTemplate: select('#movieThumbnailTpl'), selectionMode: 'single' }"> </div> ...

My HTML: <div id="listViewBoxOffice" data-win-control="WinJS.UI.ListView" data-win-options="{ itemTemplate: select('#movieThumbnailTpl'), selectionMode: 'single' }"> </div> ...

  1. listview doesn't scroll
  2. listview doesn't scroll flutter
  3. listview doesn't show items c#
  4. listview doesn't show
  5. listview doesn't show items
  6. listview doesn't scroll android
  7. listview doesn't update
  8. listview doesn't scroll inside scrollview
  9. listview doesn't update c#
  10. listview doesn't show columns
  11. listview doesn't update android
  12. listview doesn't scroll xamarin
  13. listview does not change
  14. list view doesn't
  15. listview setitemchecked doesn't work
  16. flutter listview doesn't scroll
  17. javafx listview doesn't show items
  18. wpf listview doesn't update
  19. wpf listview doesn't scroll
  20. c# listview doesn't show columns

I am trying to return an array of values for the first <td> of every <tr> within <tbody> of my table. A demo here (attempt, not working) http://jsfiddle.net/vJqeT/1/ My JS Code: ...

I am trying to return an array of values for the first <td> of every <tr> within <tbody> of my table. A demo here (attempt, not working) http://jsfiddle.net/vJqeT/1/ My JS Code: ...

  1. return array values javascript
  2. return array values java
  3. return array values excel
  4. return array values php
  5. return array values c#
  6. return array values
  7. return array values js
  8. return array values in python
  9. return array values function
  10. php return array values only
  11. return all array values php
  12. php return array values by key
  13. return all array values c#
  14. sql return array values
  15. jquery return array values
  16. return array of unique values javascript
  17. return multiple values array javascript
  18. excel formula return array values
  19. return array of matching values excel
  20. php function return array values

I am trying to convert markup for a listing of businesses in which every line is a <p> and only the business name is also wrapped in <strong>. Instead I want each business' entire listing ...

I am trying to convert markup for a listing of businesses in which every line is a <p> and only the business name is also wrapped in <strong>. Instead I want each business' entire listing ...