Skip to content

Instantly share code, notes, and snippets.

@shiffman
Last active September 29, 2015 15:00
Show Gist options
  • Select an option

  • Save shiffman/5e5183189a569bb35b24 to your computer and use it in GitHub Desktop.

Select an option

Save shiffman/5e5183189a569bb35b24 to your computer and use it in GitHub Desktop.
Making multiple objects without the constructor function, which one do you like?
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);
}
}
}
}
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);
}
}
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