function constructor: new
使用new運算子建立物件
物件建立的方式
1.new Object
2.object literals
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 4 years ago
Was this helpful?