Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7975145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:34:13+00:00 2026-06-04T08:34:13+00:00

Coffeescript is placing the var directive on the wrong place. I have tried placing

  • 0

Coffeescript is placing the var directive on the wrong place. I have tried placing braces on the functios but no success. Here is the coffeescript code:

jQuery (->

  $(".item-scaffold-edit").live("click", (=>
    element = $(this)
    cont = element.data("cont")
    url = element.data("url")
    $.ajax(url,
      dataType: "html"
      success: (data, textStatus, jqXHR) ->
        $("##{cont}").html(data)
        $("##{cont}").data("url", url))))

  $(".item-menu").live("click", (=>
    element = $(this)
    cont = element.data("cont")
    url = element.data("url")
    if url isnt $("##{cont}").data("url")
      $.ajax(url,
        dataType: "html"
        success: (data, textStatus, jqXHR) ->
          $("##{cont}").html(data)
          $("##{cont}").data("url", url)
          $("#navbar-left li").removeClass("active")
          element.parent().addClass("active"))))
)

It generates this:

(function () {
  jQuery((function () {
    var _this = this;
    $(".item-scaffold-edit").live("click", (function () {
      var cont, element, url;
      element = $(_this);
      cont = element.data("cont");
      url = element.data("url");
      return $.ajax(url, {
        dataType: "html",
        success: function (data, textStatus, jqXHR) {
          $("#" + cont).html(data);
          return $("#" + cont).data("url", url);
        }
      });
    }));
    return $(".item-menu").live("click", (function () {
      var cont, element, url;
      element = $(_this);
      cont = element.data("cont");
      url = element.data("url");
      if (url !== $("#" + cont).data("url")) {
        return $.ajax(url, {
          dataType: "html",
          success: function (data, textStatus, jqXHR) {
            $("#" + cont).html(data);
            $("#" + cont).data("url", url);
            $("#navbar-left li").removeClass("active");
            return element.parent().addClass("active");
          }
        });
      }
    }));
  }));
}).call(this);

But it should generate this:

(function () {
  jQuery((function () {    
    $(".item-scaffold-edit").live("click", (function () {
      var cont, element, url;
      var _this = this;
      element = $(_this);
      cont = element.data("cont");
      url = element.data("url");
      return $.ajax(url, {
        dataType: "html",
        success: function (data, textStatus, jqXHR) {
          $("#" + cont).html(data);
          return $("#" + cont).data("url", url);
        }
      });
    }));
    return $(".item-menu").live("click", (function () {
      var cont, element, url;
      var _this = this;
      element = $(_this);
      cont = element.data("cont");
      url = element.data("url");
      if (url !== $("#" + cont).data("url")) {
        return $.ajax(url, {
          dataType: "html",
          success: function (data, textStatus, jqXHR) {
            $("#" + cont).html(data);
            $("#" + cont).data("url", url);
            $("#navbar-left li").removeClass("active");
            return element.parent().addClass("active");
          }
        });
      }
    }));
  }));
}).call(this);

Anyone knows what’s wrong with my coffeescript code????

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T08:34:14+00:00Added an answer on June 4, 2026 at 8:34 am

    As far as I can tell from your example, you currently have:

    foo -> bar => element = $(this)
    

    which generates:

    foo(function() {
      var _this = this;
      return bar(function() {
        var element;
        return element = $(_this);
      });
    });
    

    but you would like it to generate:

    foo(function() {
      return bar(function() {
        var _this = this;
        var element;
        return element = $(_this);
      });
    });
    

    That would be identical to this:

    foo(function() {
      return bar(function() {
        var element;
        return element = $(this);
      });
    });
    

    which you can generate using:

    foo -> bar -> element = $(this)
    

    eg, change the => into a ->. The documentation for the “fat arrow” is here, which explains how it differs from the normal arrow.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following CoffeeScript code: class Person secret = 0 constructor: (@name, @age,
Here is my CoffeeScript: jQuery -> $(form).submit (e) -> e.preventDefault() email = $(#email).val() return
Here's my CoffeeScript code: $(document).ready -> SearchView = Backbone.View.extend tagName: form className: search events:
I'm new to Coffeescript, and I have a question about Ajax. jQuery -> api
I have a function written in coffeescript that used to work fine but now
I'm interested in dabbling in CoffeeScript , but I'd rather not have to recompile
How would you extend a class using CoffeeScript, but have the construction arguments passed
Warning: Code is in Coffeescript. I hope that's ok. I have a model, Song
Playing a little with coffeescript and Rails 3.1.0.rc4. Have this code: yourMom = (location)
I have the following CoffeeScript code example: class TestClass constructor: () -> @list =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.