0
var myfunction = function (obj1){

   init = function(){
     ///object operation
     func1();
   }

   func1 = function(){
      some operation
   }

}

In the above code there is a function called func1, defined inside myfunction operates on some object. Inside myfunction(), func1() is called to change the object, I want to call this object directly.

4
  • do you want to access obj1 inside func1? Commented Mar 7, 2018 at 10:32
  • I want to access func1 outside of myfunction which still acts on the same object Commented Mar 7, 2018 at 10:33
  • return func1. check closures. Commented Mar 7, 2018 at 10:34
  • read the answer here: stackoverflow.com/a/111111/3975492 Commented Mar 7, 2018 at 10:35

1 Answer 1

1

var func1 = ''
var myfunction = function(obj1) {
  func1 = function(p, v) {
    return p + ' - ' + v;
  }
  var init = function(data) {
    return func1(obj1, data);
  }
  return init;
}
var d = myfunction('Hellow');
var result = d('world')
console.log('Inside call ', result)
console.log('Dirct call', func1('Hellow', 'World'))

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.