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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:54:48+00:00 2026-06-09T01:54:48+00:00

This is how I create objects from a hash of properties: var object =

  • 0

This is how I create objects from a hash of properties:

var object = new function (data) {
  var self = this;
  self.property = data.property;
  self.anotherProperty = data.anotherProperty;

  self.method = function () { return 'something'; }
  self.update = function (newData) {
     //what is here ? 
     //i could have written:
     self.property = newData.property;
     self.anotherProperty = newData.anotherProperty;
     //but why not reuse the constructor?
   }
};

I wonder how to reuse this function (constructor) to update an object from hash.
So that:

object.update(newData) 

would update current object properties from newData hash the same way it is done in the constructor function.

  • 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-09T01:54:50+00:00Added an answer on June 9, 2026 at 1:54 am

    By giving the constructor a name?

    function MyNotReallyClass(data){
      var self = this;
      self.property = data.property;
      self.method = function () { return 'something'; }
      self.update = MyMyNotReallyClass;
    };
    

    you can can now call

    var obj = new MyNotReallyClass(data);
    var obj2 = new MyNotReallyClass(data);
    

    and

    obj.update(data);
    

    i hope this helps.. i not 100% sure, because i’m learning too.. but yeah try it 😉

    edit: after reading this comment of you: “But that would return a new instance, wouldn’t it? Which i don’t want.”

    i think you can write the Update function and call it in your constructor

    var object = new function (data) {
      var self = this;
      self.update = function (newData) {  
       self.property = data.property;
       self.method = function () { return 'something'; }
       // and other things You want to do in constructor and update
      }
      self.update(data);
    }
    

    ;

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

Sidebar

Related Questions

Say in JavaScript I create a simple object: function MyObj() { this.prop = property;
I ran the code to create the generically related objects from this demo: http://www.djangoproject.com/documentation/models/generic_relations/
I have this test case def setUp(self): self.user = User.objects.create(username=tauri, password='gaul') def test_loginin_student_control_panel(self): c
Currently I have this code var App = Ember.Application.create(); App.user = Ember.Object.create({ people: customers
I want to create a new object using this $procedure = new ${$s.'\\'.$p}; It
I need to suck data from stdin and create a object. The incoming data
I'm looking to create a 32-bit hash of some data objects. Since I don't
I have objects which create other child objects within their constructors, passing 'this' so
I want to do something like this create type Item as object ( id
Consider statement: String s=new String(abc); Will this statement creates two String objects namely abc

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.