0

I have this structure

function foo() {
    var obj = [];
    var text = '...';
    text = text.replace(/.../g,matching_fn);
}

function matching_fn($match, $match1, $match2) {
    // i need obj here
}

I tried matching_fn use (obj) in the replace, but that didnt work.

How can I pass additional variables into my matching_fn?

2
  • 2
    Easiest way would be to define matching_fn inside foo Commented Aug 11, 2023 at 10:51
  • dang! I completely forgot functions inside functions in javascript :D thx Commented Aug 11, 2023 at 10:57

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.