# Moving function from outside to inside

**URL:** https://forum.kirupa.com/t/moving-function-from-outside-to-inside/640440
**Category:** web dev
**Created:** [September 9, 2019, 4:15pm UTC](https://forum.kirupa.com/t/moving-function-from-outside-to-inside/640440 "2019-09-09T16:15:47Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![clo](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/clo/32/9759_2.png) [@clo](https://forum.kirupa.com/u/clo)
#### Post date: [September 9, 2019, 4:15pm UTC](https://forum.kirupa.com/t/moving-function-from-outside-to-inside/640440/1 "2019-09-09T16:15:47Z")

</div>

I have this function working outside of the class App extends Component, but I want to move it inside since I can’t call an inner function from the outside:

```auto
    function moveToSelection(selected){
      for(let indexPath of selected){
        indexSet.add(indexPath.index);
      }
      console.log(indexSet);
    }

```

I am triggering it here:

```auto
    <TableView
              columns={COLUMNS}
              dataSource={ds}
              renderCell={renderCell}
              onSelectionChange={moveToSelection}
            / >

```

I tried just removing the “function” deceleration when moving it inside, but there seems to be more involved?

---

<div class="post-metadata">

### Author: ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)
#### Post date: [September 9, 2019, 6:23pm UTC](https://forum.kirupa.com/t/moving-function-from-outside-to-inside/640440/2 "2019-09-09T18:23:51Z")

</div>

That depends on how you’re moving it and where. Then if you’re trying to access a class method inside, whether or not you’ll have context issues (value of `this`) which is likely that you will.

Probably the easiest way to go about it is to move it into the class as a method and then change the handler to

```javascript
    onSelectionChange={event => this.moveToSelection(event)}

```

That should account for most problems.

---

<div class="post-metadata">

### Author: ![clo](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/clo/32/9759_2.png) [@clo](https://forum.kirupa.com/u/clo)
#### Post date: [September 9, 2019, 9:08pm UTC](https://forum.kirupa.com/t/moving-function-from-outside-to-inside/640440/3 "2019-09-09T21:08:01Z")

</div>

Got it, thank you!
