# Combining classes and instance mode in p5js?

**URL:** <https://discourse.processing.org/t/combining-classes-and-instance-mode-in-p5js/38006>\
**Category:** Coding Questions\
**Created:** [July 17, 2022, 6:18pm UTC](https://discourse.processing.org/t/combining-classes-and-instance-mode-in-p5js/38006 "2022-07-17T18:18:41Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [July 17, 2022, 6:37pm UTC](https://discourse.processing.org/t/combining-classes-and-instance-mode-in-p5js/38006/2 "2022-07-17T18:37:30Z")

</div>

> [@basicvisual](#):
>
> How is the syntax usually with classes when dealing with the instance mode?

> [@Make class get all functions of p5.js](https://discourse.processing.org/t/make-class-get-all-functions-of-p5-js/12558/2):
>
> It doesn’t seem you’re trying to expand p5js’ API, but rather you wanna access its API from inside your class, right? If you’re using the instance mode style approach: [Global and instance mode · processing/p5.js Wiki · GitHub](http://Github.com/processing/p5.js/wiki/Global-and-instance-mode) Your classes are gonna need to request the current sketch’s p5 reference in their constructor, something like this: class Snake { constructor(p) { this.p = p || p5.instance; } display() { const { p } = this; p.fill(0xff).circle(p.width - 50 \>\> 1, p…

---

_[View the full topic](https://discourse.processing.org/t/combining-classes-and-instance-mode-in-p5js/38006)._
