1

I'm relatively new to JavaScript and I'm running into an issue where I am trying to call a function from a file where it is also being exported. How do I call this function? It's important that I am able to call this function from this file as well as export it for other uses. Thanks a ton for help on this!

I have added the relevant code below:

module.exports.handleCreatedTs = function(criteria, newSearch){  
    ...Lots of Calculations happen here...
}

module.exports.handleDateAndTermsDueDate = function(criteria, newSearch, isTermsDueDate){
var tempSearchObj = {};
handleCreatedTs(criteria, tempSearchObj); //This is where the exception is thrown

if(isTermsDueDate){
    newSearch.termsDueDate = tempSearchObj;
}
else{
    newSearch.date = tempSearchObj;
}
}

module.exports.handleInvoiceSupplierName = function(criteria, newSearch){
    if(criteria.operator != "equals"){
        return; //Not going to handle this
    }

    newSearch.supplierOrg.push({text: criteria.value, value: criteria.value});
}

1 Answer 1

1

You don't have a variable in your code handleCreatedTs(). You have an anonymous function assigned to, module.exports.handleCreatedTs().

You could call it with module.exports.handleCreatedTs(), but it's probably cleaner define the named function first and add it to module.exports if you plan on calling it from within the module.

function handleCreatedTs(criteria, newSearch){  
   // ...Lots of Calculations happen here...
}

// you can call handleCreatedTs()

// export the function:
module.exports.handleCreatedTs = handleCreatedTs
Sign up to request clarification or add additional context in comments.

1 Comment

That makes perfect sense. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.