1

If i have a certain object say:

function object1(){

  function func(){...}

 *rest of objec1 content*  

 ...}

 exports.func=func;  //<---this is wrong (compiler error);

is there a way for me to export func() from outside object1 bounds?

or,within the object1 bounds, and in this case, how to use it from another place?

1
  • Asking technical questions 101: What compiler error? Commented Dec 17, 2011 at 21:17

1 Answer 1

4

You've omitted part of your source, but what you have looks fine if I fill in the blanks:

function object1(){

  function func(){...}

  exports.func=func; 
}

Something needs to call object1 at some point, e.g.:

object1();

or

new object1();

...in order for the exports.func = func; line to run, but that's fine provided you do it.

Or did you mean this doesn't work:

function object1(){

  function func(){...}

}

exports.func=func; 

If so, of course not, there's no func symbol defined in the scope where you're using it. You'd have to do something like the first code block above.

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

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.