> For the complete documentation index, see [llms.txt](https://zurassic.gitbook.io/10x-developer/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://zurassic.gitbook.io/10x-developer/javascript/coffeescript.md).

# CoffeeScript

more coffeescript tricks: <https://gist.github.com/dfurber/993584>

### iterate

* loop array: `for item in arr` or `for item, index in arr`
* loop object: `for prop, value of obj` or `for own property, value of object` (use hasOwnProperty())

### fat arrow in coffeescript

* read [this](http://webapplog.com/understanding-fat-arrows-in-coffeescript/)
* use => when we need @ to be the object in which method is written; use-> when we need @ to be the object in which method is executed.

### String with format

```coffeescript
print = """
  1st line
  2nd line
  #{supports interpolation}
  last line
  """
```

### Instance method, variables

```coffeescript
class Songs
  _titles: 0    # instance var, Although it's directly accessible, the leading _ defines it by convention as private property.
  get_count: ->
    @_titles # access instance var
  call_another_method: ->
    return @get_count() # call another instance method
```

### How to write function as a part of parameter

```coffeescript
Router.go 'home', -> 
  this.render 'home'
, 
  name: 'h'
  old: 'b'
```

## reverse for loop

coffeescript reverse for loop: `for i in [arr.length-1..0] by -1` [iterations in coffeescript](http://discontinuously.com/2012/05/iteration-in-coffeescript/)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://zurassic.gitbook.io/10x-developer/javascript/coffeescript.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
