创建对象的实例与创建相同类型的对象相同吗?

时间:2017-09-29 20:58:49

标签: javascript

我必须创建一个对象,三个对象和数组实例。

创建具有以下属性的巡航对象:
巡航日期,
游轮目的地,
巡航说明,
Cruise URL,
船名,
船舶描述,
发货地址, 价

制作三个巡航物体实例 创建三个实例的数组。

根据我的理解,我创建了一个包含所有属性的巡航对象,我必须再创建三个对象实例。

我做了以下事情。创建实例是否意味着创建相同类型的对象?

    function Cruise(cruise_Date, cruise_Destination, cruise_URL, ship_Name, ship_Description, ship_url, price ) {
        this.cruise_Date = cruise_Date;
        this.cruise_Destination = cruise_Destination;
        this.cruise_URL = cruise_URL;
        this.ship_Name = ship_Name;
        this.ship_Description = ship_Description;
        this.ship_url = ship_url;
        this.price = price
  }


    var myCruise = new cruise("16 March 2018", 

        '<a href="#">4 Night Bahmas cruise </a>', 
        "You know the name, the laid-back attitude and where to find them, but you’ll just have to visit The Bahamas to truly appreciate this classic cruise destination. On this 700-strong string of sun-splashed islands dotting the blue Atlantic, the living’s easy. (And it’s not bad on a Bahamas cruise either!) The central port of Nassau is the bustling capital of the country — bustling is a relative term, of course — while Freeport is all chill, all the time. And nothing is as delightfully desolate as Half Moon Cay and Princess Cays: pure private-destination paradise", 

        "https://www.ncl.com/cruise-destinations/bahamas-florida-cruises?cid=PS_TSI_CAL_DST_GOO-g_LEN_SRH_DESTBAF_3%20night%20bahamas%20cruise_NA_189086496943&kshid=998d4956-0345-4c42-88fb-0f1ce25bfbf9&kwid=659072&anchor=NA&gclid=Cj0KEQjw3rfOBRDJruDR8Ljm7e0BEiQAam-GsPAAXfpiBInuQfwSq6ZOe4U2KBmlRbc08kFl-gFJIBQaAtvn8P8HAQ", 

        '<a href="#">Majesty of the sea </a>', "MS Majesty of the Seas is a Sovereign-class cruise ship owned by Royal Caribbean Cruises Ltd and operated by Royal Caribbean International. ", "https://www.royalcaribbean.com/cruise-ships/majesty-of-the-seas",
        '$' + 169);  

    var myCruise2 = new cruise("Cruise_Date", "Cruise_Destination", "Cruise_Description", "Cruise_URL", "Ship_Name", "Ship_Description", "Ship_URL", "Price");

    var myCruise3 = new cruise("Cruise_Date", "Cruise_Destination", "Cruise_Description", "Cruise_URL", "Ship_Name", "Ship_Description", "Ship_URL", "Price");



    list = new Array("Departs", "Destination", "Ship", "Price from");
    instances = new Array(myCruise, myCruise2, myCruise3);

    function displayList(the_date, ) {
        // body...
    }

预期产出:

enter image description here

1 个答案:

答案 0 :(得分:0)

创建对象时的代码存在一些问题。你需要有一个名为cruise()的对象构造函数来实现它。通常,您将对象构造函数大写。另外,我怀疑他们是否打算给你提供与属性名称相同的每个属性的值。如果你要给出一个巡航物体的实例,你会给它一个真实的目的地,比如&#34;巴哈马&#34;等等。对象构造函数看起来像这样:

&#13;
&#13;
function Cruise(date,destination,descr,url,name,price){
  this.cruiseDate = date;
  this.cruiseDestination = destination;
  this.cruiseDescription = descr;
  this.cruiseUrl = url;
  this.cruiseName = name;
  this.cruisePrice = price;
}
&#13;
&#13;
&#13;

至于创建一个对象数组,在用它们的实际值创建对象的实例后,你可以把它们放在一个数组文字中,除非你应该用另一种方式做

var instances = [myCruise,myCruise2,myCruise3];