CodingTrain / CodingTrain/Suggestion-Box

How to pass parameters from objects in new ES6 Javascript

Open
#842 1 comment 0 reactions 0 assignees View on GitHub
Question
Dominant language
No language data
Stars
570
Forks
85
PR merge metrics
No merged PRs in 30d

Description

**HI can someone plz help with this.
Recently watched The Doting Train Video abt ES6 classes with arguments and stuff. I had this doubt about, how to work around this syntax jargon.**

am using **p5.js**
```
b1 = new Bubble(data1);
b2 = new Bubble(data2);
```
I also have data1 for b1 and data2 for b2. How can I write this down?

```
class Bubble {
constructor(x, y, r) {
this.x = x,
this.y =y,
----
}
move() {
this.x = this.x + random(-5, 5);
this.y = this.y + random(-5, 5);
}
show() {
ellipse(this.x, this.y, this.r*2);
}
}
```
where data1 and data2 are similar in structure but have different values

```
function data1() {
this.x = 100,
this.y = 50,
this.r =10
}
```
Is there any **elegant** **method** of writing this? Thanks again! :D

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.