Fix "do" example #22

Open
wants to merge 1 commit into
from

Conversation

Projects
None yet
1 participant

joliss commented Sep 24, 2012

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 :)
Fix "do" example
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.

```coffee
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 :)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment