This repository was archived by the owner on Nov 12, 2024. It is now read-only.
Coding style and performance #415
Answered
by
slmjkdbtl
oaklandgit
asked this question in
Q&A
|
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 |
Answered by
slmjkdbtl
Nov 13, 2021
Replies: 1 comment 1 reply
|
They're exactly the same, although for the first one I'd write it in add([
{
update() {
// ...
},
},
])instead of |
1 reply
Answer selected by
oaklandgit
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
They're exactly the same, although for the first one I'd write it in
instead of
onUpdate()inadd()to be more succinct.