es5通过构造函数方法生成对象
function Person(name, age) {
this.name = name;
this.age = age
}
Person.prototype = {
showName() {
return '我的名字叫:' + this.name
},
showAge() {
return '我的今年:' + this.age
}
}
let person = new Person('学上星辰', 18)
console.log(person.showName())
console.log(person.showAge())
es6通过class生成对象
class point{
constructor(name,age){
this.name=name ;
this.age=age;
}
showName() {
return '我的名字叫:' + this.name
}
showAge() {
return '我的今年:' + this.age
}
}
let p=new point("学上星辰",18)
console.log(p.showName())
console.log(p.showAge())