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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:14:46+00:00 2026-06-14T19:14:46+00:00

I am using jQuery and I am still pretty new to JavaScript. I am

  • 0

I am using jQuery and I am still pretty new to JavaScript. I am implementing an object as the following:

MyObject = {
  properties     : [{}],
  resetProperties: function resetProperties() { this.properties = [{}] }
};

As you can see in the above code I can reset the properties by running MyObject.resetProperties() but, in order to do that, I state two times the [{}] variable. How should I accomplish the same thing without repeating that code?


Update

I tried to do the following:

MyObject = {
  properties       : this.propertiesDefault,
  resetProperties  : function resetProperties() { this.properties = [{}] },
  propertiesDefault: [{}]
};

but I get “TypeError: invalid 'in' operand MyObject.properties” and I am not sure that is the right way to proceed.

  • 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-14T19:14:48+00:00Added an answer on June 14, 2026 at 7:14 pm

    It seems to me that it would be impossible to avoid having your default / reset properties as a separate object to the one that will be modified.

    I would recommend having a default value, and cloning it in your initialisation and reset function. Since you tagged your question with jQuery, I assume you are happy to clone the object with that:

    MyObject = {
        defaultProperties : [{}],
        properties : jQuery.extend(true, {}, this.defaultProperties),
        resetProperties: function() { 
            this.properties = jQuery.extend(true, {}, this.defaultProperties);
        }
    };
    

    See this Stack Overflow question for more information on cloning objects:

    What is the most efficient way to deep clone an object in JavaScript?

    This is the documentation for jQuery.extend:

    http://docs.jquery.com/Utilities/jQuery.extend

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

Sidebar

Related Questions

I am still pretty new to using jQuery to do anything, but I have
So I'm using this pretty standard jquery plugin pattern whereby you can grab an
I am still fairly new to jQuery so the following may seem pretty basic
I have created a function outside of $(document).ready() , but am still using jQuery
I'm pretty new to javascript / ajaax / jquery, but I was able to
I am using the following function in my jquery code $('#columns').each(function (index) { alert('here');
using jquery's .post i send do my php code an object that with var_dump
Using jquery, how can I change the color of these elements to red if
Using jQuery, how can I get the selected item's value in a select when
Using jQuery, how can I get the input element that has the caret's (cursor's)

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.