类
类的概念
- 基本语法
- 类的继承
- 静态方法
- 静态属性
以上是核心特性 - getter
- setter
{
function Fn(name,age){
this.name=name;
this.age=age;
}
var fn = new Fn('Leo',20)
}
{
class Parent{
}
}
{
class Parent{
constructor(name='hello'){
this.name = name
}
}
let v_parent = new Parent('v');
console.log('构造函数',v_parent);
}
{
class Parent{
constructor(name='hello'){
this.name = name
}
}
class Child extends Parent{
}
console.log('继承',new Child())
}
{
class Parent{
constructor(name='hello'){
this.name = name
}
}
class Child extends Parent{
constructor(name='child'){
super(name);
this.type = 'child';
}
}
console.log('继承',new Child())
}
{
class Parent{
constructor(name='hello'){
this.name = name
}
get longName(){
return '999'+this.name
}
set longName(value){
this.name = value;
}
}
let v = new Parent();
console.log('getter',v.longName);
v.longName = 'nihao';
console.log('setter',v.longName);
}
{
class Parent{
constructor(name='hello'){
this.name = name
}
static tell(){
console.log('tell')
}
}
Parent.tell()
}
{
class Parent{
constructor(name='hello'){
this.name = name
}
}
Parent.type='test';
console.log('静态属性',Parent.type);
}