# Creating a class with multiple constructors and static variables in JavaScript

**URL:** <https://discourse.processing.org/t/creating-a-class-with-multiple-constructors-and-static-variables-in-javascript/21156>\
**Category:** Coding Questions\
**Created:** [May 22, 2020, 2:24am UTC](https://discourse.processing.org/t/creating-a-class-with-multiple-constructors-and-static-variables-in-javascript/21156 "2020-05-22T02:24:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![AndJ](https://avatars.discourse-cdn.com/v4/letter/a/bc8723/32.png) [@AndJ](https://discourse.processing.org/u/AndJ)\
**Post date:** [May 22, 2020, 2:24am UTC](https://discourse.processing.org/t/creating-a-class-with-multiple-constructors-and-static-variables-in-javascript/21156/1 "2020-05-22T02:24:46Z")

</div>

I am familiar with Processing/Java but am trying to learn more p5.js/JavaScript. I am creating a class that, in Java, has multiple constructors with the same number of arguments with different data types.

Example:

```auto
class Card {
public class Card implements Comparator<Card> {
	
	public final static int SPADES = 0;
	public final static int HEARTS = 1;
	public final static int CLUBS = 2;
	public final static int DIAMONDS = 3;
	
	private int suit;
	private String card;
	private int value;
	
	public Card(int suit, String card) {
        //implementation not shown
	}
	
	public Card(int suit, int value) {
        //implementation not shown
	}

    //other methods not shown
}

```

I was wondering if there is any way to do something like this in JavaScript as you don’t explicitly state the variable type in the constructor.

Additionally, I was working in the p5.js web editor and started to try to make a class with static variables as such:

```auto
class Card {
  static SPADES = 0;
  static HEARTS = 1;
  static CLUBS = 2;
  static DIAMONDS = 3;
}

```

But I’m getting an error on line 2 ("Class properties must be methods. Expected “(” but instead saw “=”), but when I try to run this on normal JavaScript it says it’s fine. Maybe I’m just missing something…

Thank you for any help.

---

<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:** [May 22, 2020, 2:40am UTC](https://discourse.processing.org/t/creating-a-class-with-multiple-constructors-and-static-variables-in-javascript/21156/2 "2020-05-22T02:40:14Z")

</div>

> [@AndJ](#):
>
> , I was working in the p5.js web editor…

If you wanna have full access to the JS language, use something else: 😏

> [@Error Affecting All Programs](https://discourse.processing.org/t/error-affecting-all-programs/21115/4):
>
> May I suggest you to try out other online editors: angel[OpenProcessing.org](http://OpenProcessing.org)
