The first do in the example is redundant (and requires methods to be null or undefined), and the other ones don't do anything because they're not taking parameters. Instead, you need a do (method) -> call, analogous to the IIFE ((function(method) { ... })(methods[i])) in the JS code.
Here's a demo.
class Frame
methods = null
do (methods = ['remove', 'show', 'hide', 'stop']) ->
for method in methods then do ->
Frame.prototype[method] = ->
for i in [0...1] then do ->
console.log method
(new Frame).remove() # => stop :(
methods = ['remove', 'show', 'hide', 'stop']
for method in methods
do (method) ->
Frame.prototype[method] = ->
for i in [0...1]
console.log method
(new Frame).remove() # => remove :)
The first
do
in the example is redundant (and requiresmethods
to be null or undefined), and the other ones don't do anything because they're not taking parameters. Instead, you need ado (method) ->
call, analogous to the IIFE ((function(method) { ... })(methods[i])
) in the JS code.Here's a demo.