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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:02:54+00:00 2026-05-26T09:02:54+00:00

I was writing some CoffeeScript just now, and getting a strange error: TypeError: Thing(param)

  • 0

I was writing some CoffeeScript just now, and getting a strange error:


TypeError: Thing(param) is not a constructor

But it is! And when I try it in the console:

var that = new Thing(param);
that.doesSomething();

After a bit of confusion, I looked through the compiled source and found out that coffee compiles that = new Thing param to that = new(Thing(param));. Weird; I’ve never seen that before. So I promptly try it: and tada! Now I can replicate:

var that = new(Thing(param));
that.previousLineErrorsOut();

(Incidentally, the CoffeeScript generator on its home page generates the new Thing() form. The plot thickens…)

I also try it out with native constructors (new Worker("somefile") and new(Worker("somefile"))), which behave “correctly”, that is, there’s no difference between the two forms.

So I’m thoroughly confused: what’s new()? Why is it failing in some cases? Why does CoffeeScript transform my perfectly fine new into new()?

  • 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-26T09:02:54+00:00Added an answer on May 26, 2026 at 9:02 am

    new takes an expression representing a constructor and optionally a list of arguments enclosed in parentheses. For example:

    new Thing;   // equivalent to next line
    new Thing(); // most common form
    new (function() {})(); // calls the anonymous function as a
                           // constructor with no arguments
    new (function() {});   // equivalent to previous; if no arguments are
                           // specified to new, it will call with no arguments
    

    When you do this:

    new(Thing(param));
    

    It’s trying to run the result of calling Thing with the argument param as a constructor with no arguments. The parentheses after the new make Thing(param) the expression representing the constructor. As Thing does not return a constructor in your case, it fails. It’s roughly equivalent to this:

    var clazz = Thing(param);
    var instance = new clazz();
    

    I do not know why CoffeeScript transforms it that way.

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

Sidebar

Related Questions

I am writing some unit tests and I'm getting an exception thrown from my
I'm writing some code to do some stuff and I'm pretty sure its not
I'm writing some code to manipulate the Windows clipboard. The first thing I do
Writing some XML documentation for a predicate helper class. But I can't figure out
Writing some test scripts in IronPython, I want to verify whether a window is
While writing some C code, I decided to compile it to assembly and read
I was writing some ASP.NET control when I came to the scenario where I
I'm writing some documentation in Markdown, and creating a separate file for each section
I'm writing some data acquisition software and need a gui plotting library that is
I am writing some code to determine whether a network domain is registered. For

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.