如果他们在重新加载当前页面之前有任何未保存的电子邮件,我会尝试提示使用。未保存的电子邮件存储在称为未保存的哈希中。我在 CoffeeScript 中编写了脚本。
如果我使用此代码
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?
CoffeeScript 被翻译为:
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 返回字符串而不是函数?