CodingTrain / CodingTrain/Suggestion-Box
How to pass parameters from objects in new ES6 Javascript
- 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.