Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix "do" example #22

Open
wants to merge 1 commit into from

1 participant

@joliss

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 :)
@joliss joliss 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 :)
```
e094e67
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 24, 2012
  1. @joliss

    Fix "do" example

    joliss authored
    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 :)
    ```
This page is out of date. Refresh to see the latest.
Showing with 4 additions and 3 deletions.
  1. +4 −3 2012/09/actually-YOU-dont-understand-lexical-scope.md
View
7 2012/09/actually-YOU-dont-understand-lexical-scope.md
@@ -193,10 +193,11 @@ for (var i=0; i<methods.length; i++) {
And in CoffeeScript you write:
```coffeescript
-do (methods = ['remove', 'show', 'hide', 'stop']) ->
- for method in methods then do ->
+methods = ['remove', 'show', 'hide', 'stop']
+for method in methods
+ do (method) ->
Frame.prototype[method] = ->
- for element in elements then do ->
+ for element in elements
this[element][method]()
```
Something went wrong with that request. Please try again.