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();
添加回答
举报