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();
相關文章
相關標籤/搜索