# JS Classes and Event Handlers?

**URL:** <https://forum.freecodecamp.org/t/js-classes-and-event-handlers/110424>\
**Category:** General\
**Created:** [April 28, 2017, 7:52pm UTC](https://forum.freecodecamp.org/t/js-classes-and-event-handlers/110424 "2017-04-28T19:52:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![msmith1114](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/msmith1114/32/49628_2.png) [@msmith1114](https://forum.freecodecamp.org/u/msmith1114)\
**Post date:** [April 28, 2017, 7:52pm UTC](https://forum.freecodecamp.org/t/js-classes-and-event-handlers/110424/1 "2017-04-28T19:52:15Z")

</div>

So im just starting to really use Object Oriented Methods in my code, figured better now than later.

However…im trying to really think of when things should be in my class, vs separate functions vs just on the `"document.onready()"`

That being said, im doing this for Tic-Tac-Toe (my first implementation was honestly kinda hacky) so I wanted to rewrite it from scratch and make it something “worth showing off”.

So for something like a “Board” class, (in which I return whats in the tile/if the tile is empty/etc…) should I be placing event handlers in this class (Im instantiating the class of course) or is it better to put them within the `document.ready` scope?

Trying to figure out best practices here, I’d PREFER to put them in the class, but is that even really an option?

---

<div class="post-metadata">

**Author:** ![mirkoacimovic](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/mirkoacimovic/32/45427_2.png) [@mirkoacimovic](https://forum.freecodecamp.org/u/mirkoacimovic)\
**Post date:** [May 7, 2017, 8:04pm UTC](https://forum.freecodecamp.org/t/js-classes-and-event-handlers/110424/2 "2017-05-07T20:04:28Z")

</div>

Yes, you can make a class called Board 🙂  
class Board {  
constructor(){  
// init here all fields  
}  
playNextMove(pos, type){  
// logic for next turn  
}  
}

You see the pattern here. Rewrite it so then you can instantiate Board with :  
var myBoard = new Board();  
myBoard.playNextMove( … );

Hope I gave you some insights 🙂

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 17, 2021, 8:53pm UTC](https://forum.freecodecamp.org/t/js-classes-and-event-handlers/110424/3 "2021-01-17T20:53:15Z")

</div>


