Class by function constructor. All members are public.
// Lets create some class and objects from it
function Person(name, age){
this.name = name;
this.age = age;
}
Person.prototype.greeting = function(){
console.log("Hi my name is " + this.name + ' and my age is ' + this.age);
}
var Person1 = new Person('Evgeni', 32);
var Person2 = new Person('Cion', 60);
var Person3 = new Person('Navit', 31);
Person1.greeting();
Person2.greeting();
Person3.greeting();
// Lets inherit from Person to Employee
function Employee(name, age, job){
Person.call(this, name, age);
this.job = job;
}
Employee.prototype.greeting = function(){
console.log("Hi my name is " + this.name + ', my age is ' + this.age + ' and my job is ' + this.job);
}
var developer = new Employee('Matan', 30, 'Full Stack');
developer.greeting();