JavaScript中的构造函数的使用
function Person(name,age){
this.name = name;
this.age = age;
this.showID = function (){
console.log("My name is " + this.name);
console.log("I'm " + this.age +" years old");
}
}
let Ulrich = new Person('Ulrich',22);
Ulrich.showID();
输出结果: