Javascript CoffeeScript onbeforeunload响应函数不是字符串

Javascript CoffeeScript onbeforeunload响应函数不是字符串,javascript,browser,coffeescript,onbeforeunload,Javascript,Browser,Coffeescript,Onbeforeunload,如果他们在重新加载当前页面之前有任何未保存的电子邮件,我会尝试提示用户。未保存的电子邮件存储在名为未保存的散列中。我用咖啡脚本写脚本 如果我使用这个代码 window.onbeforeunload = () -> return "Your emails are not saved. Click \"Save Email\" on any email to save them all. If you would like to discard your emails, jus

如果他们在重新加载当前页面之前有任何未保存的电子邮件,我会尝试提示用户。未保存的电子邮件存储在名为未保存的散列中。我用咖啡脚本写脚本

如果我使用这个代码

  window.onbeforeunload = () ->
    return "Your emails are not saved.  Click \"Save Email\" on any email to save them all.  If you would like to discard your emails, just leave this page"  if unsaved.count > 0
而不是用我得到的信息提示我:

function ( data, fn ) {
        return arguments.length > 0 ?
            this.on( name, null, data, fn ) :
            this.trigger( name );
    }

Are you sure you want to reload this page?
咖啡脚本翻译为:

window.onbeforeunload = function() {
  if (unsaved.count > 0) {
    return "Your emails are not saved.  Click \"Save Email\" on any email to save them all.  If you would like to discard your emails, just leave this page";
  }
};

如何让CoffeeScript返回字符串而不是函数?

这与CoffeeScript无关。属性
window.onbeforeunload
要求函数返回字符串或void值,但如果
unsaved.count,这实际上与CoffeeScript无关。属性
window.onbeforeunload
要求函数返回字符串或无效值,但如果
unsave.count@muistooshort我的大脑一定短路了,你完全正确:)+1因为这句话,我差点在公共交通上笑出声来。^^顺便说一句,那是乌拉哈拉吗?@muistoshort我的大脑一定短路了,你完全正确:)+1我差点在公共交通上笑出声来,因为这句话^顺便说一句,那是乌拉哈拉吗?还有别的事情发生了,您的咖啡脚本中没有任何内容会生成您的
return$(“form.edit\u email\u template”).first().submit。看一看a。还有一些事情正在发生,你的咖啡脚本中没有任何东西会生成你的
return$(“form.edit\u email\u template”)。first().submit。看一看。
return $("form.edit_email_template").first().submit;
if (unsaved.count > 0) {
    return 'your emails are not saved.';
} else if (window.onbeforeunload) {
    $("form.edit_email_template").first().submit();
}