Skip to content

Bug with backtick #2009

@MissileSilo

Description

@MissileSilo

Consider this code:

class jQueryCalendar
  saveDate: (inputField) ->
    alert 'Saving Date' + $(inputField).val()

  initCalendarObjects: ->
    params =
      onSelect: (dateText, inst) =>
        @saveDate `this`
    $('.timelineCalendar').datepicker params

After running coffee -c -b on this file, the following javascript is generated:

var jQueryCalendar;

jQueryCalendar = (function() {

  function jQueryCalendar() {}

  jQueryCalendar.prototype.saveDate = function(inputField) {
    return alert('Saving Date' + $(inputField).val());
  };

  jQueryCalendar.prototype.initCalendarObjects = function() {
    var params,
      _this = this;
    params = {
      onSelect: function(dateText, inst) {
        return _this.saveDate(_this);
      }
    };
    return $('.timelineCalendar').datepicker(params);
  };

  return jQueryCalendar;

})();

Notice that what was in backticks incorrectly replaced. "this" was replaced with "_this"

A workaround is to put a space after the backtick: this instead of this

But it seems like this is a bug that needs to be fixed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions