1 回答

TA貢獻1865條經驗 獲得超7個贊
按照您在此處制作它的方式,它是一個范圍內的功能......這意味著您無法在您嘗試訪問它的范圍內“看到”它。
您需要使其成為“方法”或將其附加到“此”。
// We normally require/import things at the top, but not nessesarily.
// const PromptSync = require("prompt-sync");
class Customer {
constructor() {
this.shoppingBasket = [];
this.startShoppingPropertyFunction = () => {
// If imported at top, use this instead:
// const prompt = new PromptSync();
const prompt = require("prompt-sync")();
const itemName = prompt("What item is this?");
const itemPrice = prompt("How much is it?");
const taxExemption = prompt("Is this a food, book or medical product?");
console.log(`Your item is ${itemName}`);
}
}
startShoppingMethod() {
// If imported at top, use this instead:
// const prompt = new PromptSync();
const prompt = require("prompt-sync")();
const itemName = prompt("What item is this?");
const itemPrice = prompt("How much is it?");
const taxExemption = prompt("Is this a food, book or medical product?");
console.log(`Your item is ${itemName}`);
}
}
const myCustomer = new Customer();
myCustomer.startShoppingMethod();
myCustomer.startShoppingPropertyFunction();
添加回答
舉報