Can CoffeeScript Be Translated into This Piece of JavaScript?

Posted by tangrui on Stack Overflow See other posts from Stack Overflow or by tangrui
Published on 2012-03-20T10:17:06Z Indexed on 2012/03/20 11:29 UTC
Read the original article Hit count: 178

Filed under:
|
function abc() {
    var a = 1;
    var func = function() {
        var a = 2;
    }
    func();
    alert(a);
}

Pay attention to the var, in the piece of code, the result of a will be 1, but if the var is omitted, the result will be 2, but I found Coffee not able to translate to this.

For example the following:

abc = ->
    a = 1
    func = ->
        a = 2
        return
    func()
    alert(a)
    return

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about coffeescript