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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:34:43+00:00 2026-05-26T03:34:43+00:00

This is an academic question, to clarify my understanding of JavaScript. A function object

  • 0

This is an academic question, to clarify my understanding of JavaScript.

A function object can be assigned attributes once it is created. However, is it possible to create a function object with attributes in one step?

For example,

function someFunction(){
}

var someFunctionObject=someFunction;


someFunctionObject.attr1="attr 1";

alert(someFunctionObject.attr1); /* "attr 1"

Here the attribute is being added in the second step, after the object has been created. Is it possible to achieve this in one step?

  • 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-26T03:34:44+00:00Added an answer on May 26, 2026 at 3:34 am

    The short answer is no. Read below for the explanation.

    The end result of your code is something like:

    var myFunctionObject = {
        prop1: 'foo',
        prop2: 'bar',
        construct: "alert('function body')"
    };
    myFunctionObject(); // should alert
    myFunctionObject.prop1; // 'foo'
    

    A function definition/declaration actually does something very similar – it creates an object with the [[Construct]] property set to the actualy body of the function. But, this is just an implementation detail and you cannot access or set that [[Construct]] property separately, so you cannot define other properties in one-go (it would require additional syntax and there is none available).

    But, you can set properties from inside the function, if that’s what you need. For example, this would be useful for caching:

    function getSomething() {
        if (getSomething.prop) return getSomething.prop;
        return getSomething.prop = fetchResource();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is kind of an academic question, so feel free to exit now. I've
This may seem to be an academic question, but still I would be very
This question is mostly academic. I ask out of curiosity, not because this poses
This is more of an academic inquiry than a practical question. Are there any
This is an academic question. In the report for GCC bug 38764 , there
This is a pretty academic question. I'm wondering how the browser is implemented as
Just an academic question. I'm curious what version of this code is better (faster)
This is more of an academic question about performance than a realistic 'what should
This is an almost academic question but I'm curious as to its answer. Suppose
This is a bit more of an academic question. Indeed I am preparing 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.