# How to access p5js functions when using ES6 modules

**URL:** <https://discourse.processing.org/t/how-to-access-p5js-functions-when-using-es6-modules/21359>\
**Category:** Coding Questions\
**Created:** [May 28, 2020, 7:51am UTC](https://discourse.processing.org/t/how-to-access-p5js-functions-when-using-es6-modules/21359 "2020-05-28T07:51:44Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![dansumption](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/dansumption/32/9365_2.png) [@dansumption](https://discourse.processing.org/u/dansumption)\
**Post date:** [July 2, 2020, 6:33pm UTC](https://discourse.processing.org/t/how-to-access-p5js-functions-when-using-es6-modules/21359/5 "2020-07-02T18:33:12Z")

</div>

Thanks for your replies @GoToLoop and sorry for taking so long to get back on this… life intervened!

Your tips sent me in the correct direction, which put very simply was to set a `setup` and `draw` method on the global `window` object. I’m not sure quite where I got my previous approach from, but I copied it from somewhere, where instead the `setup` and `draw` methods were instantiated in something like the following way:

```auto
const sketch = processing => {
  processing.setup = () => {
    ...
  }

  processing.draw = () => {
    ...
  }
}

const myP5 = new p5(sketch);

```

I then had to iron out a few race conditions which I had been experiencing mainly as a result of my initial approach, but once I’d done that then it worked even better than before, plus I managed to clean the code of hundreds of ugly instances of (for example) `this.processing.circle(...` and replace them with a far more straightforward `circle(...`

Coincidentally, changing my approach to the one you recommended also solved the other mystery problem I’d been seeing, detailed in this post: [Setup method runs twice - #3 by dansumption](https://discourse.processing.org/t/setup-method-runs-twice/21275/3)

BTW if you’re interested to see what I ended up making with all this new knowledge (and I’m very proud of it), here’s the music video I made entirely using p5js: [https://youtu.be/rdbgckSmlAo](https://youtu.be/rdbgckSmlAo)

Thanks again!

---

_[View the full topic](https://discourse.processing.org/t/how-to-access-p5js-functions-when-using-es6-modules/21359)._
