1 回答

TA貢獻(xiàn)1865條經(jīng)驗(yàn) 獲得超7個贊
按照您在此處制作它的方式,它是一個范圍內(nèi)的功能......這意味著您無法在您嘗試訪問它的范圍內(nèi)“看到”它。
您需要使其成為“方法”或?qū)⑵涓郊拥健按恕薄?/p>
// 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();
添加回答
舉報(bào)