andrewplummer/Sugar — Issue #105: Feature request: function.returns(val)
Author: D1plo1d
Created: 2012-02-07 04:12:25+00:00
State: open

A problem (well, to me it looks like a problem) I often come across in trying to write concise code when using jquery.bind and coffeescript is that I need to return a specific value from a function. Often times i don't care what the function would normally return and just need to satisfy jquery's need for me to return true or false to propagate an event properly. I find my usual way (see bellow) of doing this unnecessarily verbose and that bugs me.

So what I propose is that instead of this:

```coffeescript
$("body").bind "keydown", "ctrl+shift+s", =>
@_openLocalFileModal("save")
return false
```

Sugar adds a function.returns function that takes a function and wraps it in a pre-specified return value so that we can do nice little one liners like this:

```coffeescript
$("body").bind "keydown", "ctrl+shift+s", => @_openLocalFileModal.returns(false)("save")
```