/* 以前面向对象的写法 */
function User(name, pass) {
this.name = name;
this.pass = pass;
}
User.prototype.showName = function() {
console.log(this.name);
};
User.prototype.showPass = function() {
console.log(this.pass);
};
let wxs = new User("武兴师", "imycode");
wxs.showName();
wxs.showPass();
/*现在es6写法
*/
class Custom {
constructor(name, pass) {
this.name = name;
this.pass = pass;
}
showName() {
console.log(this.name);
}
showPass() {
console.log(this.pass);
}
}
let w = new Custom("imycode", "code");
w.showName();
w.showPass();