Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can i do optional function

i need to do optional function.
How can i do like this:

  console.log(db.(x==true ? input(...) : ["no function"]).query(...));
// if x is true console.log(db.input(...).query(...));
// if x is false console.log(db.query(...));

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You don’t need to compare x with true:

console.log((x ? db.input(...) : db).query(...));

You want to call query either on db or on db.input(...) depending on x.

Example:

const db = { input() { return { query() { return 'db.input(...).query(...)'; } } }, query() { return 'db.query(...)'; } };

console.log((true ? db.input() : db).query());
console.log((false ? db.input() : db).query());
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading