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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:25:05+00:00 2026-05-21T23:25:05+00:00

Can you call a function as an object? For example: function Tip(txt){ this.content =

  • 0

Can you call a function as an object? For example:

function Tip(txt){      
    this.content = txt;  
    this.shown = false;  
}

And:

var tip = new Tip(elem.attr('title'));

My questions:

  1. Can you call new for a function, as for an object?
  2. The use of “this” is made possible, because we use that function as an object?
  • 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-21T23:25:06+00:00Added an answer on May 21, 2026 at 11:25 pm

    You are looking for the constructor concept.

    All functions in JavaScript are objects and can be used to create objects:

    function make_person(firstname, lastname, age) {
        person = {};
        person.firstname = firstname;
        person.lastname = lastname;
        person.age = age;
        return person;
    }
    make_person("Joe", "Smith", 23);
    // {firstname: "Joe", lastname: "Smith", age: 23}
    

    However, in order to create new objects of a particular type (that is to say, that inherit a prototype, have a constructor, etc), a function can reference this and if it is called with the new operator then it will return an object with all of the attributes that are defined on this in the function – this in such cases references the new object we are creating.

    function make_person_object(firstname, lastname, age) {
        this.firstname = firstname;
        this.lastname = lastname;
        this.age = age;
        // Note, we did not include a return statement
    }
    

    The key difference to note between make_person and make_person_object is that calling new make_person() (as opposed to simply make_person()) will not do anything different … both will produce the same object. Calling make_person_object() without the new operator however, will define your this attributes on the current this object (generally window if you are operating in the browser.)

    Thus:

    var Joe = make_person_object("Joe", "Smith", 23);
    console.log(Joe); // undefined
    console.log(window.firstname) // "Joe" (oops)
    
    var John = new make_person_object("John", "Smith", 45);
    console.log(John); // {firstname: "John", lastname: "Smith", age: 45}
    

    Also, as @RobG points out, this way of doing things creates a reference to the prototype property of make_person_object on each “Person” we create. This enables us to add methods and attributes to persons after the fact:

     // Assuming all that came before
    make_person_object.prototype.full_name = "N/A";
    make_person_object.prototype.greet = function(){ 
        console.log("Hello! I'm", this.full_name, "Call me", this.firstname); 
    };
    John.full_name // "N/A"
    John.full_name = "John Smith"; 
    make_person_object.full_name // Still "N/A"
    John.greet(); // "Hello! I'm John Smith Call me John"
    

    Convention has it that constructor functions like make_person_object are capitalized, singularized and “nouned” (for lack of a better term) — thus we would have a Person constructor, rather than a make_person_object which might be mistaken for an ordinary function.

    See also:

    • The new operator
    • bobince’s great introduction to subclassing in JavaScript (both with and without prototype inheritance.)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I call a function from an object in javascript, like for example
I need a function that I can call when somthing is done, for example
I can call a function directly (I'll use alert as an example) like so
Can I call a function from lisp from a library written in c or
How can I call a C++ function from a C program, is it possible?,
I know I can call the GetVersionEx Win32 API function to retrieve the Windows
How can I bind arguments to a Python function so that I can call
Possible Duplicate: How can I pre-set arguments in JavaScript function call? (Partial Function Application)
A regular function can contain a call to itself in its definition, no problem.
I noticed that you can call Queue.Synchronize to get a thread-safe queue object, but

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.