es6面向对象
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script>
// function User(name, pass) {
// this.name = name;
// this.pass = pass;
// }
// User.prototype.login = function () {
// console.log('登录成功');
// }
class User {
constructor(name, pass) {
this.name = name;
this.pass = pass;
}
login() {
console.log('登录成功');
}
}
let p = new User('zs', 123);
console.log(p.name);
console.log(p.pass);
p.login();
</script>
</head>
<body>
</body>
</html>
es6面向对象2
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script>
// function User(name, pass) {
// this.name = name;
// this.pass = pass;
// }
// User.prototype.login = function () {
// console.log('登录成功');
// }
class User {
constructor(name, pass) {
this.name = name;
this.pass = pass;
}
login() {
console.log('登录成功');
}
}
let p = new User('zs', 123);
console.log(p.name);
console.log(p.pass);
p.login();
class VIPUser extends User {
constructor(name, pass, level) {
super(name, pass);
this.level = level;
}
download() {
console.log('下载');
}
}
let v = new VIPUser('ls', '123456', 8);
v.login();
v.download();
</script>
</head>
<body>
</body>
</html>
es6面向对象3
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script>
// function User(name, pass) {
// this.name = name;
// this.pass = pass;
// }
// User.prototype.login = function () {
// console.log('登录成功');
// }
class User {
constructor(name, pass) {
this.name = name;
this.pass = pass;
}
login() {
console.log('登录成功');
}
}
let p = new User('zs', 123);
console.log(p.name);
console.log(p.pass);
p.login();
class VIPUser extends User {
constructor(name, pass, level) {
super(name, pass);
this.level = level;
}
download() {
console.log('下载');
}
}
let v = new VIPUser('ls', '123456', 8);
v.login();
v.download();
console.log(v instanceof User);
</script>
</head>
<body>
</body>
</html>
网友评论