es6 class 笔记


 var House1 = function(){

    this.doors =3;

    this.windows = 10;

    this.color = "blue";

    }

class House {
    constructor() {
        this.name = "House";
        this.doors = 3;
        this.windows = 10;
        this.color = "blue";
        this.hello = function(){
            console.log("hello, I am a" + this.name);
            console.log("I have " + this.doors  + "color(s)");
            console.log("I am " + this.color);
        }
    }
}
var myhourse = new House()
console.log(myhourse.doors)
console.log(myhourse.windows)
console.log(myhourse.color)
myhourse.hello();

猜你喜欢

转载自my.oschina.net/u/3734107/blog/1579969