I'm currently doing a school project, the project revolves around easy access to skills in an organisation. I have created a class called Employee, this class have a predefined set of employees stored in localStorage (because no access to databases). The list of employees is outputted via a function that creates a table of the list.
Now I want to create a class called Skills, I want the Skills class be instantiated in my Employee class. The purpose of this is that employees should be able to enter a site and write in their skills, the skills has to be stored to a employee and the saved in localStorage and the updated in the table. So my problem revolves around using the right syntax / method of instantiation a class into another class..
class Skills{
constructor(sId){
this.sId = sId;
}
}
if (localStorage.getItem("Skills") == null) {
var skillList =[];
var skillListString = JSON.stringify(skillList);
localStorage.setItem("skills",skillListString);
} else {
var skillListString = JSON.parse(localStorage.getItem("Skills"));
class Employee {
// vi bruger en constructor funktion for at lave en opskrift på objekter af en bestemt type.
//this metoden benyttes til at referere til det tilhørende objekt
constructor(name, gender, department, yy, email, skills) {
this.name = name;
this.gender = gender;
this.department = department;
this.email = email;
this.skills = [];
}
}
//Employee Database "Localstorage"
if(localStorage.getItem("Employee") == null) {
let employeeList = [];
employeeList.push (new Employee("Simon", "Male", "HR", 1999, "[email protected]"));
employeeList.push (new Employee("Mads", "Male","IT", 1999, "[email protected]"));
employeeList.push (new Employee("Jessica", "Female", "Sales",1998, "[email protected]"));
employeeList.push (new Employee("Benjamin", "Male","IT", 1997, "[email protected]"));
if(localStorage.getItem("Employee") == null) {
employeeListString = JSON.stringify(employeeList);
localStorage.setItem("Employee", employeeListString);
employeeList = JSON.parse(localStorage.getItem("Employee"));
}
} else {
employeeList = JSON.parse(localStorage.getItem("Employee"));
document.querySelector("#employees").appendChild(buildTable(employeeList));
}
new SomeClass().Employeeclass in your code. Do the same withSkills.