1.2.5.3.危險小叮嚀:「new 」與函數
//建立物件 function Person() { this.firstname = 'John'; this.lastname = 'Doe'; } //建立空物件 //呼叫person, 並把this指到person上 var john = Person(); //印出undefined console.log(john) //出現錯誤 Person.prototype.getFullName = function() { return this.firstname + ' ' + this.lastname }
Last updated