js基礎

1構造函數函數

function Student(name) {
    this.name = name;
    this.hello = function () {
        alert('Hello, ' + this.name + '!');
    }
}

//調用
var xiaoming = new Student('小明');
xiaoming.name; // '小明'
xiaoming.hello();
相關文章
相關標籤/搜索