class Example {
constructor(a,b) {
this.a = a;
this.b = b;
console.log(this);
}
aa = this.a;
static bb = 10;
sing(){
return this.a+this.b;
}
}
console.log(Example.bb)
let exa = new Example(2,1);
console.log(exa.aa);
console.log(exa.sing());
返回值为对象
class Test {
constructor(){
this.sum = (a, b) => {
console.log(a + b);
}
}
aa = 10;
}
let te = new Test();
let te1 = new Test();
console.log(te);
console.log(te1);
console.log(te==te1);
console.log(te.__proto__==te1.__proto__);
console.log(te);
te.sum(3,4)
console.log(typeof new Test());
console.log(typeof Test);
console.log(new Test() instanceof Test);
class Example{
constructor(){
return new Test();
}
}
console.log(new Example() instanceof Example);
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
</body>
<script type="text/javascript">
// class Example {
// constructor(a,b) {
// this.a = a;
// this.b = b;
// console.log(this);
// }
// aa = this.a;
// static bb = 10;
// sing(){
// return this.a+this.b;
// }
// }
// console.log(Example.bb)
// let exa = new Example(2,1);
// console.log(exa.aa);
// console.log(exa.sing());
// 返回值为对象
// class Test {
// constructor(){
// this.sum = (a, b) => {
// console.log(a + b);
// }
// }
// aa = 10;
// }
// let te = new Test();
// let te1 = new Test();
// console.log(te);
// console.log(te1);
// console.log(te==te1);
// console.log(te.__proto__==te1.__proto__);
// console.log(te);
// te.sum(3,4)
// console.log(typeof new Test());
// console.log(typeof Test);
// console.log(new Test() instanceof Test);
// class Example{
// constructor(){
// return new Test();
// }
// }
// console.log(new Example() instanceof Example);
class Example{
constructor(a,b) {
this.a = a;
this.b = b;
}
get a(){
console.log('getter');
return 99;
}
get b(){
console.log('getter');
return 98;
}
set a(user){
console.log('setter');
console.log(user);
this.aa = user;
}
set b(user){
console.log('setter');
console.log(user);
this.bb = user;
}
sing(){
this.a = this.a;
}
}
// let exa = new Example(10,20);
let exa = new Example(5,10);
// exa.sing();
console.log(exa);
// console.log(exa.age);
</script>
</html>