English 中文(简体)
未含蓄地归还“false”
原标题:coffeescript not implicitly returning "false"

我正试图在斯特林特类型/类别中增加一种方法,在这种方法中,我可以从南盟的扼杀物中排除碎片。

String::getUrlParams = ->                        # line 1 
    false unless ( params = @.split( ? )[1] )    # line 2
    # ...

在 Chrome·科索尔,当我蓄意用无布卢拉的扼杀手段来形容这一方法时,我期望它只是回谎。

"http://dns.com/".getUrlParams();

但它通过一条线。 2. 结 论

if I change line 2 to

   return false unless ( params = @.split( ? )[1] ) # line 2`

then it does return false and stops the function at line 2

Any idea why coffeescript isn t returning false and halts the function in the first version?

Thank you

最佳回答

Coffeescript returns only the last function statement. If something follows some statement, that you want to return in middle of function, then you should do that explicitly.

--Short thoughts-- In short - Coffeescript compiler is not that smart, to predict, where you may want or may not want to return something. And same applies to most compilers now days. Also it s non-smartiness avoids most of mistakes, which would be caused because of premature return.

问题回答

暂无回答




相关问题
How do I define global variables in CoffeeScript?

On Coffeescript.org: bawbag = (x, y) -> z = (x * y) bawbag(5, 10) would compile to: var bawbag; bawbag = function(x, y) { var z; return (z = (x * y)); }; bawbag(5, 10); compiling via ...

I m trying to re-write this in CoffeeScript. Coming unstuck

function getElementsByClassName(className) { // get all elements in the document if (document.all) { var allElements = document.all; } else { var allElements = document.getElementsByTagName("...

Anonymous functions syntax in CoffeeScript

I ve been looking at CoffeeScript and I m not understanding how you would write code like this. How does it handle nested anonymous functions in its syntax? ;(function($) { var app = $....

Why are my CoffeeScript/backbone.js events not firing?

I m trying to familiarize myself with CoffeeScript and backbone.js, and I must be missing something. This CoffeeScript: MyView = Backbone.View.extend events: { "click" : "testHandler" ...

Custom compiler with maven

I m trying to make Maven2 to compile coffeescript to javascript. As far as I m concerned there is no plugin which provides compiling coffeescript. Is there a compiler-plugin for maven which can be ...

what is wrong when I compile my .coffee files

Hi there Iam using coffeeScript for my apps now and I love it but recently I ve been having a lot of trouble with compilation, Iam using it for a rails application and when I run coffee -w -c public/...

CoffeeScript on Windows?

How can I try CoffeeScript on Windows? The installation instructions are only for *nix: http://jashkenas.github.com/coffee-script/#installation EDIT: Since I asked this a while ago, many new ...

How can I compile CoffeeScript from .NET?

I want to write an HttpHandler that compiles CoffeeScript code on-the-fly and sends the resulting JavaScript code. I have tried MS [JScript][1] and IronJS without success. I don t want to use [Rhino][...

热门标签