Blogger Information
Blog 14
fans 1
comment 0
visits 4529
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
实现自有,共享,静态成员的声明与输出的类/实例演示数组与对象解构方法
叫我孙大树
Original
355 people have browsed it
// 用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)

该代码运行的数据返回如下:

屏幕截图 2022-07-24 205815.png

Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments