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

  • Home
  • SEARCH
  • 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 6863561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:47:52+00:00 2026-05-27T02:47:52+00:00

I have recently started using coffeescript with Rails and I am finding that sometimes

  • 0

I have recently started using coffeescript with Rails and I am finding that sometimes the generated javascript does not get the function safety wrapper.

Here is a sample project demonstrating it.

For example, this CS code, in index.js.coffee:

class Foo
  afunc: ->
    alert("afunc")

Correctly becomes:

(function() {
  var Foo;

  Foo = (function() {

    function Foo() {}

    Foo.prototype.afunc = function() {
      return alert("afunc");
    };

    return Foo;

  })();

}).call(this);

But this code, from other.js.coffee:

class App.Func
  ouch: ->
    alert("ouch")

becomes this un-wrapped version

  App.Func = (function() {

    function Func() {}

    Func.prototype.ouch = function() {
      return alert("ouch");
    };

    return Func;

  })();

It seems to be due to the “App.” prefix – which I can see affects naming/scope – but why is coffeescript compiling it differently…

App is defined in setup.js.coffee, like this:

window.App =
  Models: {}

Which also does not get wrapped, unless I add a class into that file too.

I am sure it must be my misunderstanding – so thanks in advance for the pointers to the manual :).

EDIT:
I created this question as I thought it might be behind some issues I was having with my backbone/coffeescript app, but it seems that it was not. As the class is linked to a public/global thing “App”, it seems to work wrapped or not. Still would be useful to know why its happening – is it by design?

  • 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-27T02:47:53+00:00Added an answer on May 27, 2026 at 2:47 am

    The “function safety wrapper” feature you are using works to prevent local variables from being set on the global namespace. Since setting an object property (App.Func) doesn’t affect the global namespace, the declaration is not wrapped in a function.

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

Sidebar

Related Questions

I have recently started to learn Objective-C and write my tests using OCUnit that
Ive recently started using Ruby on Rails for a project of mine and have
I have recently started using generics in java, and in that attempt tried to
I have recently started using VirtualBox to get my Linux environment rather than fully
I recently started using WPF and the MVVM framework, one thing that I have
I have recently started using Vim as my text editor and am currently working
I have recently started using DocCheck for checking the validity of JavaDoc's in code
We have recently started using FxCop on our code base and I am in
I have recently started using Zend Studio which has reported as warning the following
I have recently started creating an iPhone application using Appcelerator's Titanium. Since the application

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.