-
-
Save shiffman/5e5183189a569bb35b24 to your computer and use it in GitHub Desktop.
Making multiple objects without the constructor function, which one do you like?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var particles = []; | |
| function setup() { | |
| for (var i = 0; i < 10; i++) { | |
| particles[i] = { | |
| x: 100, | |
| y: 100, | |
| display: function() { | |
| ellipse(this.x, this.y, 16, 16); | |
| } | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var particles = []; | |
| function setup() { | |
| for (var i = 0; i < 10; i++) { | |
| var particle = { | |
| x: 100, | |
| y: 100, | |
| display: function() { | |
| ellipse(this.x, this.y, 16, 16); | |
| } | |
| } | |
| particles.push(particle); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var particles = []; | |
| function setup() { | |
| for (var i = 0; i < 10; i++) { | |
| particles[i] = makeParticle(); | |
| } | |
| } | |
| function makeParticle() { | |
| var particle = { | |
| x: 100, | |
| y: 100, | |
| display: function() { | |
| ellipse(this.x, this.y, 16, 16); | |
| } | |
| } | |
| return particle; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment