Quick actions

cmd+k|ctrl+k

Navigation

Languages

es6

Snippet info

Language

JavaScript

Visibility

public

Author

pheker

Created

2017-07-22T07:46:00Z

Updated

2017-07-22T07:46:00Z


//let,const Destructuring
let name = 'dog';
const park = 'www';
let dog = {name,park};
console.log("dog:\t",dog);

let cat ={
    color:'white',
    length:'24'
}
let {color,length} = cat;
console.log("color:\t"+color);
console.log("length:\t",length)

// class, extends, super
class Shape{
    //构造函数
    constructor(){//this
        this.type = 'Shape';
    }
}

class Ball extends Shape{
    
    constructor(r=0){
        super();    //从父类继承this
        this.type = 'Ball';
        this.r = r
        this.x = 0;
        this.y = 0;
    }
    run(){
        // arrow function,template
        let interval = setInterval(()=>{
            this.x++;
            this.y++;
            if(this.x>3||this.y>3){
                clearInterval(interval);
            }else{
                console.log(`[Ball]:\t${this.x},${this.y} ${this.r}`);
            }
        },33)
    }
    
    // default
    print(a = 0){
        console.log("print:\t"+a);
    }
    
    //rest
    say(...words){
        console.log("words:\t"+words);
    }
    
}

let ball = new Ball(5);

console.log("r:\t"+ball.r)

ball.run();

ball.print();

ball.say("No","Zuo","No","Die")






INFO