joshmarinacci / webxr-workshops

Modular workshop series for teaching WebXR (VR & AR)
MIT License
55 stars 2 forks source link

audio_basic - slightly simpler syntax #33

Open NickPax opened 6 years ago

NickPax commented 6 years ago

Don't need to make a box var, as the 'el' parameter picks up the entity. So this works ok: on(box,'click', () => box.components.sound.playSound())

joshmarinacci commented 6 years ago

I don't understand. Your example still has a box variable.

NickPax commented 6 years ago

Hi Josh, all I meant was that you don't need this line: const box = $("#box")

joshmarinacci commented 6 years ago

True, you could write it as

on($(‘#box”),’clicked’,() => $(#box).components.blah)

However I prefer to use an explicit variable to make it easier for people to understand. In practice I would do the shortened version in my own code, but I’ve found one line arrow functions to be tricky for newbies to understand.

NickPax commented 6 years ago

Even this works: on(box,'click', () => box.components.sound.playSound()) Which is nice because there's less actual code, but I see what you're saying.