//建立對象---->實例化一個對象,的同時對屬性進行初始化 var per=new Person("小紅",20);
自動逸構造函數建立對象作的事情:函數
//實例對象 var per1 = { name: "小明", age: 20, sex: "男", eat: function () { console.log("吃臭豆腐"); }, readBook: function () { console.log("時間簡史") } } //調用系統的構造函數 var per2 = new Object(); per2.name = "小蘇"; per2.age = 30; per2.sex = "男"; per2.eat = function () { console.log("吃西瓜"); }; per2.play = function () { console.log("遊戲真好玩"); }; //自定義構造函數 function Person(name, age, sex) { this.name = name; this.age = age; this.sex = sex; this.play = function () { console.log("每天打遊戲"); }; }; var per = new Person("小丁", 39, "女"); console.log(per instanceof Person);