Coffeescript Jqcloud Handlers
Solution 1:
The usual CoffeeScript approach to this problem is to use do:
When using a JavaScript loop to generate functions, it's common to insert a closure wrapper in order to ensure that loop variables are closed over, and all the generated functions don't just share the final values. CoffeeScript provides the
dokeyword, which immediately invokes a passed function, forwarding any arguments.
Then just use a plain for ... in instead of the while loop so that you don't have to muck around with the indexes; something more like this:
foroinstuffdo(o)->tag_list.pushtext:o.NAMEweight:o.COUNThtml:title:"#{o.COUNT} varieties"handlers:click:->console.log("itworkedfor",o)Demo: http://jsfiddle.net/ambiguous/3W9YC/
Or you could use a loop comprehension like this:
tag_list=foroinstuffdo(o)->text:o.NAMEweight:o.COUNThtml:title:"#{o.COUNT} varieties"handlers:click:->console.log("itworkedfor",o)and avoid the push calls.
Demo: http://jsfiddle.net/ambiguous/3W9YC/1/
BTW, you can use CoffeeScript at jsfiddle.net by selecting it in the Languages panel in the sidebar.
Post a Comment for "Coffeescript Jqcloud Handlers"