Coding style and performance #415
-
Hi, I'm wondering if there are any downsides (e.g. performance impact) to this first approach (with the const player = add([
sprite("bean"),
pos(120, 80),
rotate(0),
origin("center"),
{
add() {
this.onUpdate(() => {
this.angle += 120 * dt()
})
}
}
]) as opposed to the approach provided in most of the demos and documentation: const player = add([
sprite("bean"),
pos(120, 80),
rotate(0),
origin("center"),
])
player.onUpdate(() => {
player.angle += 120 * dt()
}) The reason I prefer the former is that it encapsulates the behavior with the object. In testing a trivial example like the one above, there doesn't seem to be a performance impact but I wonder if there could be theoretically or any other reason it should be avoided. Thank you |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
They're exactly the same, although for the first one I'd write it in add([
{
update() {
// ...
},
},
]) instead of |
Beta Was this translation helpful? Give feedback.
They're exactly the same, although for the first one I'd write it in
instead of
onUpdate()
inadd()
to be more succinct.