2

js files index.js and utils.js

I have tried to do the module export solution with no luck.

To call a function in utils.js from index.js I write a the function in utils as

export.functioname = function(parms) {

...

};

If i want to call the same function internally from utils.js i can do it i have to write another identical function as: var functionname (parms) { ... }

How can i get around this and only have one function to be called externally and internally?

3
  • sorry it should read exports.functioname Commented Dec 9, 2016 at 15:24
  • You can edit your post ;) Commented Dec 9, 2016 at 15:25
  • You could just call exports.functioname(parms) within the module, as long as you define it before you call it. Commented Dec 9, 2016 at 17:18

2 Answers 2

3

You can use:

var yourfunction = function(param){
    console.log(param);
}

exports.yourfunction = yourfunction;

yourfunction("Works");

Which prints: "Works"

Sign up to request clarification or add additional context in comments.

Comments

0

Functions can be saved to variables

var moo = function(parms) {}; 

export.functioname = moo;

or

function moo(parms) {};
export.functioname = moo;

works aswell because of js closures

Comments

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.