[英]Object is not displaying values in console log
我的 class 對象未從控制台日志中的主 object 顯示
// Inventory , the main class
class Inventory{
constructor(shoe,customer){
this.shoes = [];
this.customers = [];
}
addShoes(shoe){
this.shoes.push(shoe);
}
addCustomers(customer){
this.customers.push(customer);
}
}
// Customer class
class Customer{
constructor(name,address,phone){
this.name = name;
this.address = address;
this.phone = phone;
}
}
//Shoes class
class Shoes{
constructor(brand,name,color,size){
this.brand = brand;
this.name = name;
this.colors = [];
this.sizes = [];
}
addColors(color){
this.colors.push(color);
}
addSizes(size){
this.sizes.push(size);
}
}
// Where I put in the data for the object values, to display to console log
const inventory = new Inventory();
const myko = new Customer("Myko","216 Peachtree",9144444444);
const shoes = new Shoes("Nike","Air Force 1");
shoes.addColors(["Black/Green","Blue/white","Red/Blue","White/Red"]);
shoes.addSizes([12,10,9,11]);
const newAdd = new Inventory(shoes,myko);
console.log(newAdd);
我的控制台日志顯示的內容,空數據
庫存{鞋子:Array(0),客戶:Array(0)} 客戶:Array(0)
當我在 console.log 中調用 Inventory class 時輸入數據時,我希望顯示控制台日志
庫存{鞋子:Array(1),客戶:Array(1)}
客戶:“Myko”、“216 Peachtree”、9144444444”
鞋子:“Nike”、“Air Force 1”、“Black/Green”、“Blue/white”、“Red/Blue”、“White/Red”、12、10、9、11
您沒有使用構造函數中的參數初始化庫存。 ([] 反而。)
class Inventory{
constructor(shoe,customer){
this.shoes = shoe;
this.customers = customer;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.