2

我在 Rails 应用程序中有以下内容:

# projects.js.coffee
jQuery ->
  $('#project_title').typing ->
    start: (event, element) ->
      element.css 'background', '#fa0'

    stop: (event, element) ->
      element.css 'background', '#f00'
      alert 'send request to populate samples'

    delay: 400

但是,在编译的 js 文件中,我得到以下内容:

(function() {

  jQuery(function() {
    return $('#sprinkler_word').typing(function() {
      ({
        start: function(event, element) {
          return element.css('background', '#fa0');
        },
        stop: function(event, element) {
          return element.css('background', '#f00');
        }
      });
      alert('send request to populate sprinkle samples');
      return {
        delay: 400
      };
    });
  });

}).call(this);

为什么“警报”调用不包含在“停止”功能中?我假设我的语法不正确,但我看不到在哪里。谢谢。

4

1 回答 1

2

将您的代码粘贴到“Try Coffeescript”小部件中您期望的代码,即停止函数中的警报:

jQuery(function() {
  return $('#project_title').typing(function() {
    return {
      start: function(event, element) {
        return element.css('background', '#fa0');
      },
      stop: function(event, element) {
        element.css('background', '#f00');
        return alert('send request to populate samples');
      },
      delay: 400
    };
  });
});

因此,我猜测制表符和空格会弄乱缩进。

于 2012-07-18T18:36:45.983 回答