Currently delving into the world of Object Oriented Programming in JavaScript, I recognize that there might be mistakes in my approach.
The main focus is on a single JS function (class) below:
function User() {
//Code to initialize object goes here
}
//Functions
User.prototype.getEmpId = function() {
return this.empId;
}
var myUser = new User({'empid':'1'});
console.log(myUser.getEmpId()); //Returns 1
var mynewuser = new User({'empid':'2'});
console.log(myUser.getEmpId()); //Returns 2
console.log(mynewuser.getEmpId()); //Returns 2
The issue arises from my confusion regarding why there seems to be an error. If these are indeed two separate objects, then what could be causing the conflict? You can view the complete code here.
Your assistance is greatly appreciated.