-1
Class A {
                 callUpdate() {
                               // how to call the update function from here
                 }

                 create() {

                          function update() {
                                            // do something
                          }
                 }
        }

How to call local function outside which declared inside the function?

4
  • You cannot, it's declared locally and that's where it's scoped. Commented Feb 16, 2019 at 9:19
  • If it's in a TypeScript function, then its TypeScript, not JavaScript (it will work the same way as a JS function since TS is a superset of JS and is usually transpiled to JS) Commented Feb 16, 2019 at 9:21
  • Thanks @connexo. I just declared callUpdate() as local function of create() Commented Feb 16, 2019 at 9:25
  • stackoverflow.com/questions/8817872/… Commented Feb 21, 2019 at 10:04

1 Answer 1

0

May be it s help you

class A {
                     callUpdate() {
                        this.create()();
                     }

                     create() {

                              return function update() {
                                   console.log('do something')                          }
                     }
            }
    let newA = new A();

    newA.callUpdate();
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.