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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:12:09+00:00 2026-05-23T10:12:09+00:00

Sometimes we need to call a function by its name. I can do it

  • 0

Sometimes we need to call a function by its name. I can do it in plain JavaScript as below:

global=this
function add(a,b){return a+b}
global['add'](1,2)

Which works as expected and add() gets called.

Equivalent CoffeeScript code might can be written as below.

global=@
add=(a,b)->a+b
global['add'](1,2)

which compiles to JavaScript as:

(function() {
  var add, global;
  global = this;
  add = function(a, b) {
    return a + b;
  };
  global['add'](1, 2);
}).call(this);

…and it doesn’t work.

Microsoft JScript runtime error: Object doesn't support this property or method

Is there an easy solution to this problem?

Note:

  1. I am not running the code in a browser therefore there is no window object. But in plain JS I can always capture the global scope by assigning global=this and then get the function pointer from it.

  2. One solution in CoffeeScript I found is by declaring all functions as member of a global object like global.add=[function definition]. But then I have to normally call the function as global.add(). And it’s more boiler plate than necessary.

Is there a simple hack? Or any simpler solution?

  • 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-23T10:12:09+00:00Added an answer on May 23, 2026 at 10:12 am

    Your add is a local variable. Use

    @add=(a,b)->a+b
    

    to attach it to the global object. Since global is the global scope of your script you can still call add without prefixing it with global..

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

Sidebar

Related Questions

I need to call a library function that sometimes won't terminate within a given
I notice sometimes with my parent/child objects or many-to-many relationships, I need to call
I'm using the navigator.geolocation.getCurrentPosition(function) api in firefox 3.6. When i try to call this
i've learned that you can register body onload like this: window.addEventListener('load', function, capture); //
I am making a cross-domain JSON(P) call by using JavaScript to add a <script>
I have a program which during it's run sometimes needs to call python in
We allow users to write code which sometimes calls jQuery.ready(function(){..}) multiple times. It seems
I sometimes need to use Visual Studio when I have limited screen real estate
I sometimes need to look for information for a special portion of code. When
I sometimes need to debug JS in other browsers, and it would be really

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.