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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:00:35+00:00 2026-05-31T04:00:35+00:00

I have created an object through literals and instantiating using ‘new’ operator. But that’s

  • 0

I have created an object through literals and instantiating using ‘new’ operator. But that’s not working. Here is my code:

var rectangle = { 
    upperLeft : { x : 2, y : 2 },
    lowerRight : { x : 4, y : 4}
}
var r=new rectangle;
alert(r.upperLeft.x) // will yield 2

I have tried using Parentheses after the object name while instantiating:

var r=new rectangle;

But that’s also not working. I have tried creating object using function statement and that’s working fine, but I want to do it this way. Help.

  • 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-31T04:00:37+00:00Added an answer on May 31, 2026 at 4:00 am

    rectangle is, as you noticed, an Object Literal. It’s not a Constructor function, it’s a single instance of Object. If you want rectangle to have more instances, use something like:

    function Rectangle(ul,lr){
      var default = {x:0,y:0};
      return {
              upperLeft: ul || default, 
              lowerRight: lr || default 
             };
    }
    
    var r1 = new Rectangle({x:2,y:2},{x:4,y:4}),
        r2 = new Rectangle({x:3,y:3},{x:5,y:5}),
        r3 = new Rectangle;
    
    r1.upperleft.x; //=> 2
    r2.upperleft.x; //=> 3
    r3.upperLeft.x = 5;
    r3.upperLeft.y = 7;
    alert(r3.upperLeft.x; //=> 5
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have created an IE band object (toolbar) that is working well. however, when
We have a classic ASP page that is instantiating a .Net object through a
I have an ExpenseType object that I have created with the following migration: class
I have tree control object created using CTreeCtrl MFC class. The tree control needs
I have a stdClass object created from json_decode that won't return the right number
I've created a object that I'd like to have accessible from wherever the request-object
I have created an IDbContext object that is provided to my IRepository implementations. The
I have created a function that loops through a set of returned JSON. I
I have created a UIView object using the contents of a NIB file like
I have created a simple List function but if I Loop through the List

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.