我已经做了很多尝试在JavaScript中理解OOP但没有成功.
到目前为止我读过的所有文章都非常混乱,而且在JS中没有简单地解释OOP
作为在JavaScript中理解OOP的最后一次尝试,有人可以将以下代码转换为JS,请求?
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;
}
}
Run Code Online (Sandbox Code Playgroud)
里面主()
Derived person = new Derived("John", "Doe", 25);
System.out.println("My name is " + person.firstName + " " + person.lastName + " and …Run Code Online (Sandbox Code Playgroud)