This is a continuation. My old question.
This is my function that creates a new student object:
function student(id, name, marks, mob, home){ this.id = id; this.name = name; this.marks = marks; this.contacts = {}; this.contacts.mob = mob; this.contacts.home = home; this.toContactDetailsString = function(){ return this.name +':'+ this.mob +', '+ this.home } }
I would like to create a copy of an object when it is initialized inside this object: I came up with this:
function student(id, name, marks, mob, home){ this.id = id; this.name = name; this.marks = marks; this.contacts = {}; this.contacts.mob = mob; this.contacts.home = home; this.toContactDetailsString = function(){ return this.name +':'+ this.mob +', '+ this.home } this.baseCopy = this;
But the problem is that it gives me an infinite loop of copies of the current object in baseCopy; ANd is also automatically updated when I update any attributes of my object.
1. How is it possible that I can save a copy of an object with initial values ββinside this object when it is created?
2. Is it possible to copy functions
3. I am very curious to find out if this is possible without hard coding attribute names and using pure JS
source share