You can use `Function.prototype.call` here to explicitly control the context of the function. The implementation might look like:

```diff
- function openPanel(app, selector) {
+ function openPanel(selector) {
-   menuItem = app.waitForElement(selector);
+   menuItem = this.waitForElement(selector);
    parentSection = menuItem.findElement('ancestor::section', 'xpath');
    menuItem.tap();
-   app.client.waitFor(function() {
+   this.client.waitFor(function() {
      return parentSection.location()['x'] + parentSection.size()['width'] == 0;
    });
 }
```

Usage:

```diff
- openPanel(this, 'bluetoothMenuItem');
+ openPanel.call(this, 'bluetoothMenuItem');
```