I want to have a class that can CRUD. Have methods for each operation. Use the parameters that I mention in my class.
I was hoping I could use the parameters given to the constructor in my method. How can I do that?
I might need to use a dictionary or a list to store the data properly. Any advice?
const fs = require('fs')
class Product {
constructor(productType, modelName, productPrice) {
this.productType = productType;
this.modelName = modelName;
this.productPrice = productPrice;
}
oopWrite(productType, modelName, productPric) {
const blah = [{productType, modelName, productPric}]//or use str arg;
const dataJSON = JSON.stringify(blah)
fs.writeFileSync('bleh.json', dataJSON);
return dataJSON;
}
}
const product1 = new Product();
console.log(product1.oopWrite({"productType":"Laptop"}, {"modelName":"ccc"}, {"modelName":"blah"}));
This class works without the constructor. How can I make the method use the parameters passed in the constructor?
Update to my Question -> I need to instantiate the Product as:
const blah = new Product{productType, modelName, productPrice}//or use str arg;