1

Fiddle - http://codepen.io/mikethedj4/pen/BNRdVp

Today I decided to learn Coffeescript and play around making some functions, handling events, etc.

However today I got an error that says, "reserved word 'function'", and haven't figured out how to solve it.

Original:

$(function () {
    function download_to_textbox(url, el) {
        $.get(url, null, function (data) {
            el.val(data);
        }, "text");
    }
    download_to_textbox("http://code.jquery.com/jquery-latest.min.js", $("textarea"));
});

My translation:

(($) ->
  function download_to_textbox(url, el) {
    $.get(url, null, (data) ->
      el.val(data);
      }, "text");
  }
  download_to_textbox("http://code.jquery.com/jquery-latest.min.js", $("textarea"));

  $("textarea").click ->
  $(this).select();
) jQuery
1
  • There is no function keyword in CS. Commented Jun 8, 2015 at 8:49

1 Answer 1

1
$ ->
    download_to_textbox = (url, el) ->
        $.get url, null, ((data) ->
            el.val data
            return
        ), 'text'

    download_to_textbox 'http://code.jquery.com/jquery-latest.min.js', $ 'textarea'
    $("textarea").click ->
        $(this).select()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.