function makeGroup(param) {
this.group = param;
}
duplicateEmployee.makeGroup(index2);
Doing a simple duplicateEmployee.group = index2 doesn't work. Trying a method says "makeGroup is not a function."
Here's the full code for reference.
var someVar = [];
vm.contacts = ContactsService.query(employees => {
employees.forEach(employee => {
employee.groups.forEach((groupMembership, index2) => {
// getEmployee() works...
function getEmployee(param) {
return param;
}
// "makeGroup is not a function"
function makeGroup(param) {
this.group = param;
}
var duplicateEmployee = getEmployee(employee);
if (groupMembership) {
duplicateEmployee.makeGroup(index2); // this breaks it. Says makeGroup is not a function
console.log(groupMembership, index2); // index2 is working... that's the group number
someVar.push(duplicateEmployee);
}
});
});
});
vm.contacts = someVar;
Tried this and it doesn't work
function makeGroup(param1, param2) { // console.log(param2) === undefined
console.log(param1); // group number... not the employee (still useful)
console.log(this); // 'this' is the employee, so lets try this.group
this.group = param1; // still overwriting the variable
}
makeGroup.call(duplicateEmployee, index2)
duplicateEmployeeis just a variable that has whichever valueparamhas, it doesn't have a function calledmakeGroupEmployeekind of class, addmakeGroupto it's prototype, create a new class in your code, and then call that function. Also I don't get the point of creating those two functions only available in yourforEachscope.