天天看點

建構對象并向數組中添加對象

1     //數組的兩種定義方式,構造函數new或者數組直接量。
 2     //構造函數,構造對象
 3     function objStory(id,title,author,time){
 4         this.ID = id;
 5         this.Title = title;
 6         this.Author = author;
 7         this.Time = time;
 8 
 9     }
10     var arr = [];
11     arr.push(new objStory(10,"woshiwang","king","2012-01-03"));
12     arr.push(new objStory(12,"wang","los","2012-01-04"));
13     console.log(arr);      

繼續閱讀