批改状态:合格
老师批语:
// 用class创建一个类, 并实现自有,共享,静态成员的声明与输出
class sum {
num2 //共享变量
jia() {
return this.num1 + this.num2
}
jian() {
return this.num1 - this.num2
}
cheng() {
return this.num1 * this.num2
}
chu() {
return this.num1 / this.num2
}
// 自有成员
constructor(num1, num2) {
this.num1 = num1
this.num2 = num2
}
// 静态成员
static sum2 = '666';
}
let zhi = new sum(2, 6)
console.log(zhi.chu())
console.log(sum.sum2)
// 实例演示数组与对象解构方法
// 数组结构
let [name, sex, age] = ['rhl', 'nv', '21']
console.log(name)
// 对象结构
let {red, blue, green} = {red: 1, blue: 2, green: 3}
console.log(red, blue, green)该代码运行的数据返回如下:

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号