I am trying to pass value from one page function to another Class function but its not working as expectation
detail.js
const {UserData} = require("./userData");
let commonfield="Asia Origin";
var userData= new UserData();
userData.start(commonField);
userData.js
class UserData extends Commands{
async start(field){
console.log(field);
}
}
Here You can see I tried to pass the value but its not passing the value from detail.js to userData.js class function
CodePudding user response:
You are calling the wrong function:
const {UserData} = require("./userData");
let commonfield="Asia Origin";
var userData= new UserData();
try {
const result = await userData.start(commonField); // should be start
}
catch(e) {
console.log(e);
}
class UserData extends Commands{
async start(field){
console.log(field);
return field;
}
}
As, start
is an async function to get its value you need to use await.
CodePudding user response:
**
can you remove 'async; and then check it ? i hope, it should be a work.
if not try this way...
const UserData = require("./userData.js");
let commonfield="Asia Origin";
new UserData().save("values printed");
UserData.js
class UserData extends Commands{
start(field){
console.log(field);
}
}
Commands.js
Class Commands{
fun(){console.log("abc");}
**