I'm creating an array of object type Employee, but one of the properties is not working as expected.
I'm using an array of objects of type Employee, that I define with a constructor statement block. Part of the constructor is that if no nickname property is defined, the first name is used as the nickname. Also, if no shift is defined, it is set as "1."
When I debug, I see that the nickname and shift are always set as if nothing was defined for those properties, even if they were. What gives?
The details: running on IE9, also using jquery2.1, on a Win7 machine.
Here's the code:
// make sure doc ready first
$(document).ready(function(){
function Employee(firstname, lastname, nickname, employeeID, shift, serviceTruck, pickupTruck, serviceTruckWO){
this.firstname = firstname;
this.lastname = lastname;
/*
* Check if the nickname is present. If not,
* set as lastname. Credit to SO for
* how to do this properly, ref
* http://stackoverflow.com/questions/27509/detecting-an-undefined-object-property-in-javascript
*/
if (typeof this.nickname === "undefined") {
this.nickname = this.firstname;
}
else {
this.nickname = nickname;
}
this.employeeID = employeeID;
if (typeof this.shift === "undefined") {
this.shift = "1";
}
else {
this.shift = shift;
}
this.serviceTruck = serviceTruck;
this.pickupTruck = pickupTruck;
this.serviceTruckWO = serviceTruckWO;
}
var Employees = new Array();
Employees[0] = new Employee("John", "Smith", "Smithy", "1234", "2", "ST1", "PU1", "WO1");
Employees[1] = new Employee("Jane", "Doe", "", "1235", "", "ST2", "PU2", "WO2");
});