1.2.5.1.函數建構子、「new」與 JavaScript 的歷史
function constructor: new
使用new運算子建立物件
物件建立的方式
new運算子
//建立物件
function Person() {
this.firstname = 'John';
this.lastname = 'Doe';
}
//建立空物件
//呼叫person, 並把this指到person上
var john = new Person();
//印出Person {firstname: "John", lastname: "Doe"}
console.log(john)
Last updated
Was this helpful?