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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:35:46+00:00 2026-06-05T11:35:46+00:00

Possible Duplicate: How to “properly” create a custom object in JavaScript? Sorry if this

  • 0

Possible Duplicate:
How to “properly” create a custom object in JavaScript?

Sorry if this has been answered before but I’m a bit overwhelmed by the amount of choices offered to be in regard to creating custom objects in Javascript. I’m not sure of their respective strengths or weaknesses or whether or not they differ at all.

Here are some of the different ways I have found to construct objects:

1: New Object

person = new Object()
person.name = "Tim Scarfe"
person.height = "6Ft"

person.run = function() {
    this.state = "running"
    this.speed = "4ms^-1"
}

2: Literal Notation

timObject = {
    property1 : "Hello",
    property2 : "MmmMMm",
    property3 : ["mmm", 2, 3, 6, "kkk"],
    method1 : function(){alert("Method had been called" + this.property1)}
};

3: Functions

function AdBox() {
    this.width = 200;
    this.height = 60;
    this.text = 'default ad text';
    this.prototype.move = function() {
        // code for move method goes here
    }
}
this.prototype.display = function() {
    // code
}

I even saw some more ways but they seemed less common.. As you can see I’m not exactly sure what the standard is when someone just wants a simple object with fields and methods.

Thanks for reading.

  • 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-05T11:35:48+00:00Added an answer on June 5, 2026 at 11:35 am

    The first and second options are functionally identical. Most developers choose to use the literal notation because it’s a little shorter.

    The third option is generally only used when you’re looking to create reusable objects (i.e. inheritance). In this case, the function acts as a “constructor” – which is a function that returns a new object instance that can inherit methods and properties defined in the constructor’s prototype.

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

Sidebar

Related Questions

Possible Duplicate: “Least Astonishment” in Python: The Mutable Default Argument Edit: This has nothing
Possible Duplicate: Weird “406 not acceptable” error I've been stuck on this ALL DAY!
Possible Duplicate: Nested “from” LINQ query expressed with extension methods I'm sure this has
Possible Duplicate: “Least Astonishment” in Python: The Mutable Default Argument I'm trying to create
Possible Duplicate: PHP: “Notice: Undefined variable” and “Notice: Undefined index” This code shows warnings
Possible Duplicate: Detecting an “invalid date” Date instance in JavaScript Is there is a
Possible Duplicate: What does “options = options || {}” mean in Javascript? I stumbled
Possible Duplicate: Why write <script type=“text/javascript”> when the mime type is set by the
Possible Duplicate: What does “options = options || {}” mean in Javascript? Looking at
Possible Duplicate: Why does “abcd”.StartsWith(“”) return true? Something similar to this being true caught

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.