Coffeescript ‘this’ inside jQuery .each()

jQuery.each passes the current element as second parameter of the callback, so you don’t have to reserve this for jQuery:

processRows: ->
    $("#my-table>tr").each (index, element) =>
        id = $(element).attr("id")
        @processRow id

Notice the use of the fat arrow (=>) syntax for the callback function; it binds the function’s context to the current value of this. (this in the callback function is always the same this as the one at the time you defined the function.)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)