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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:11:55+00:00 2026-06-14T22:11:55+00:00

>>> function () {} SyntaxError >>> f = function() {} f = function() {}

  • 0
>>> function () {}
SyntaxError

>>> f = function() {}
f = function() {}

>>> new function() {}
>>> Object

>>> new Function()
function anonymous() {}

>>> Function()
function anonymous() {}


>>> f = (function() { a = 10; return function() {console.log(a);} })();
>>> f()
10
undefined

>>> f = (function() { a = 10; return new Function('console.log(a)'); })();
>>> f()
undefined

Thus, I have two questions:

  1. Why is the Function constructor returning a new function even without the new operator?

  2. Are functions created with the Function constructors NOT closures?

  • 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-06-14T22:11:56+00:00Added an answer on June 14, 2026 at 10:11 pm

    Why is the Function constructor returning a new function even without the new operator?

    Calling Function() is the same as calling new Function():

    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.


    Are functions created with the Function constructors NOT closures?

    Yes, the scope of the function is set to the global environment, not to the scope of the lexical environment. See http://es5.github.com/#x15.3.2.1, step 11:

    11. Return a new Function object created as specified in 13.2 passing P as the FormalParameterList and body as the FunctionBody. Pass in the Global Environment as the Scope parameter and strict as the Strict flag.

    That means using the Function constructor is as if you declared a function in global scope, regarding the scope it can access (not regarding where the function is visible).

    This is different from using function declarations/expressions, where the scope is based on the current exectution context (http://es5.github.com/#x13):

    1. Let funcEnv be the result of calling NewDeclarativeEnvironment passing the running execution context’s Lexical Environment as the argument
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

function() { var w = new Object(), w.x = 10, y = 11; }
This function gives me the following error: SyntaxError: Invalid character '\u8203' All looks good
I get following error (SyntaxError): missing ] after element list when using eval function.
function Apple(){ this.name=apple; } function Orange(){ this.name=orange; this.apple = new Apple(); this.apple.onCalled=function(){ alert(this.name); }
function getWindowsUserName() { var WinNetwork = new ActiveXObject(WScript.Network); var urlToSite = http://localhost/index.php?nph-psf=0&HOSTID=AD&ALIAS= + WinNetwork.UserName;
Possible Duplicate: declare property as object? class core { public $dbh = new PDO(mysql:dbname=newdbnaem;host=1.1.1.1:1111,
I wanted to run a certain function as a thread, but I get SyntaxError:
I've the following vb.net function which have a syntax error in the sql commandtext
I have created an AJAX function that is used with pagination links to load
Ok, I have a large multidimensional JSON object being poured into my app, of

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.