2

This is basically the framework of my code:

var firstfunction = function () {
    function innerfunction () {
        // Do stuff here
    }
}

How do I reference innerfunction(), without changing the code mentioned supra?

3
  • What do you mean by "reference [it] by jQuery"? What exactly do you want to do with it? Commented Sep 15, 2012 at 0:51
  • @David Good point, I removed that. Commented Sep 15, 2012 at 0:52
  • Shouldn't firstfunction.innerfunction() work? Checked and NO - leaving this here for reference. Commented Sep 15, 2012 at 0:53

2 Answers 2

3

If you want to expose innerFunction as an API you could do the following:

var firstFunction = function () {
  var imPrivate = "foo"
  var innerFunction = function () {
    // do stuff
  }

  return {
    innerFunction : innerFunction
  }
}

firstFunction.innerFunction()

This would also let you create private methods, variables as well.

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

Comments

0

It seems that you're wanting to make use of currying, this is a functional programming technique where you return an function from another function i.e.:

var f1 = function() {
    return function() {
    }
}

> f1()();

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.