I've done many attempts to understand OOP in JavaScript without success.
All articles I've read so far are very confuse and not explain succintly OOP in JS
As a last attempt to understand OOP in JavaScript, can someone translate to JS the following code, pleas?
public class Base
{
public String firstName; // public scope to simplify
public String lastName; // the same as above
Base(String firstName, String lastName)
{
this.firstName=firstName;
this.lastName=lastName;
}
}
public class Derived extends Base
{
public int age; // public scope to simplify
Derived(String firstName, String lastName, int age)
{
super(firstName, lastName);
this.age=age;
}
}
Inside main()
Derived person = new Derived("John", "Doe", 25);
System.out.println("My name is " + person.firstName + " " + person.lastName + " and I have " + person.age + " years old.");
Output:
My name is John Doe and I have 25 years old.
Can you please convert this to JavaScript?
Another question: Can we have polimorphism in JavaScript?