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 6083011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:21:10+00:00 2026-05-23T11:21:10+00:00

funName = () -> $(.foo).addClass(bar); Compiles into the scope of an anonymous function. Calling

  • 0
funName = () ->
  $(".foo").addClass("bar");

Compiles into the scope of an anonymous function. Calling funName from the console results in undefined.

(function() {
  var funName;
  funName = function() {
    return $(".foo").addClass("bar");
  };
}).call(this);

What’s its reasoning for compiling like this and how do I work with it?

Also any insight on the mandatory return within functions using CoffeeScript would be great. Why is it like that? How do I need to code differently because of it?

  • 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-05-23T11:21:11+00:00Added an answer on May 23, 2026 at 11:21 am

    Mike has answered the main question here. The modular wrapper a common point of confusion for CoffeeScript newcomers, as illustrated by these related questions:

    • How do I define global variables in CoffeeScript?
    • Why use the javascript function wrapper (added in coffeescript) ".call(this)"
    • Getting rid of CoffeeScript's closure wrapper

    As to your other question: If you don’t want a function to return anything, simply make the last line of that function either return by itself or, equivalently, undefined. Either will compile to a function with no return. For instance:

    funName = ->
      $(".foo").addClass "bar"
      return
    

    compiles to

    var funName;
    funName = function() {
      $(".foo").addClass("bar");
    };
    

    Note that there is an ongoing discussion (issue 899) about a possible alternative syntax for defining no-return functions. If the current proposal were accepted, you’d be able to write your function as

    funName = -/> $(".foo").addClass "bar"
    

    If you like that syntax, you should voice your support for it.

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

Sidebar

Related Questions

I need to pass two values to a javascript function from inside another javascript
Possible Duplicate: How can I return multiple values from a function in C#? C#
Say I have classes Foo and Bar set up like this: class Foo {
Is it possible to load remote JavaScript files from the address bar? I have
Can I use type as a name for a python function argument? def fun(name,
I want to call function with arguement periodically. I tried setTimeout(fnName(),timeinseconds) ; and it
I would like to be able to call a function based on its name
Is it possible to call a php class function DIRECTLY using ajax? Something like
Inside of a static member function I need to get the type. class MyClass
I've written this decorator to deprecate a function and (optionally) provide a callable as

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.