mauricemach / coffeekup

Markup as CoffeeScript.
coffeekup.org
MIT License
1.26k stars 84 forks source link

__bind not generated in coffeescript #39

Closed tanepiper closed 13 years ago

tanepiper commented 13 years ago

In my coffeescript code, within my coffeekup template, => does not generate the __bind function within the script tag.

For example:

coffeescript ->
    foo = ->
        bar = 1
        baz = =>
            console.log bar

    foo().baz()

Exception thrown is Uncaught ReferenceError: __bind is not defined

The output is

;(function () {
    var foo;
    foo = function() {
        var bar, baz;
        bar = 1;
        return baz = __bind(function() {
            return console.log(bar);
        }, this);
    };
    return foo().baz();
})();
bmidgley commented 13 years ago

fwiw, the workaround is to add it through a script tag

script "__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };"

or maybe just include underscore.js

grncdr commented 13 years ago

Same thing for me, I'm too new to CS to know when/why it decides to generate the bind function, but I would guess that the compiler thinks it's already generated? (p.s. Thanks for the workaround!)

mauricemach commented 13 years ago

I fixed this in 0.2.4beta by including all coffeescript helpers in code generated by the coffeescript "tag". But maybe it's a better idea to keep the original behavior of generating "clean" code and requiring the addition of the helpers manually. What do you guys think?

bmidgley commented 13 years ago

I prefer the automatic code generation. I noticed another of these popped up when I did an "if x in y" so it will be nice to have that work as well without tinkering.

mauricemach commented 13 years ago

Automatic it remains then. After all, now thinking, 635 bytes are not that of an issue.