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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:57:14+00:00 2026-05-18T03:57:14+00:00

As far as I understand, in JavaScript (Gecko variant) this: var a = new

  • 0

As far as I understand, in JavaScript (Gecko variant) this:

var a = new A();

is a syntactic sugar for something like this:

var a = {};
a.__proto__ = A.prototype;
A.call(a);

Because of that, A() (which is equivalent to A.call()?) and new A() should produce two different results, like these:

>>> new Date()
Fri Nov 19 2010 01:44:22 GMT+0100 (CET) {}
>>> typeof new Date()
"object"

>>> Date()
"Fri Nov 19 2010 01:44:42 GMT+0100 (CET)"
>>> typeof Date()
"string"

So far so good.

But, core object Function behaves differently:

>>> Function('return 123;')
anonymous()
>>> typeof Function('return 123;')
"function"
>>> Function('return 123;')()
123
>>> new Function('return 123;')
anonymous()
>>> typeof new Function('return 123;')
"function"
>>> new Function('return 123;')()
123

Am I missing some trivial thing here ?

  • 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-18T03:57:14+00:00Added an answer on May 18, 2026 at 3:57 am

    JavaScript at a language level doesn’t specify a particular ‘standard’ way of using constructors. When you define your own constructor function, you can choose to have it callable as a constructor (with new), as a function (returning a new object), or make it work with either.

    Am I missing some trivial thing here?

    Not really. The Function constructor function is defined to be usable as a constructor even without new, by ECMAScript section 15.3.1:

    When Function is called as a function rather than as a constructor, it creates and initialises a new Function object. Thus the function call Function(...) is equivalent to the object creation expression new Function(...) with the same arguments.

    The Date function, on the other hand, is defined (by ECMAScript section 15.9.2) to return a string:

    When Date is called as a function rather than as a constructor, it returns a String representing the current time (UTC).

    NOTE: The function call Date(...) is not equivalent to the object creation expression new Date(…) with the same arguments.

    The NOTE is there because so many constructor functions can also be used without new. That’s not because of any over-arching thinking that all constructor functions should be allowed to work as plain functions, but because this is just what JavaScript has always done since the early Netscape days. Netscape couldn’t think of anything special for Function() to do, so it just reproduced the new functionality. They didn’t pay too much attention to making the language consistent.

    You wouldn’t design a language’s default class library like that if you were sane. But JavaScript isn’t a sane language. It’s a quick hack that got way out of hand, achieving mass popularity way before anyone spent any time refining its design. Expect it to behave consistently and you will only be disappointed.

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

Sidebar

Related Questions

As far as I understand, binding to a var in ActionScript is carried out
As far as I can understand, when I new up a Linq to SQL
As far as I know, in gcc you can write something like: #define DBGPRINT(fmt...)
I am a bit new to javascript and was trying to understand how the
As far as I understand, all JavaScript code is event-driven and executes on a
As far as I understand, every string is an object in Javascript. Still, it
As far as I understand, if I want to get my database under source
How secure is it to use self-signed certificates? As far as I understand it,
As far as variable naming conventions go, should iterators be named i or something
I was just trying to learn and understand jQuery source code (so far with

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.