给你个模板:
function A(name, age) {
// 显式的声明在了构造函数里
this.name = name;
this.age = age;
this.getMl = function() {
return `${this.name}今年${this.age}岁了`;
};
}
// 函数被new以后,该函数叫构造函数
const ml = new A("于朦胧", 27);
A.prototype.job = "歌手";
A.prototype.run = function() {
return `${this.name}身为${this.job},竟然跑了1005米,用时2.5分钟`;
};
// new 这个动作就叫实例化,返回的对象就是实例化对象
console.log(ml.run());