jeudi 26 janvier 2017

Associating Javascript classes/objects with HTML widgets/graphical objects, a la AS3

Please forgive me if this is too general or too poorly conceived. I'm coming from the (now defunct) world of OOP AS3 and would like to bring some of the techniques I learned there for structuring code to my Javascript coding.

One of the nifty things about AS3 was that it was quite easy to associate a Class with an on-screen graphical object, aka MovieClip. There was a one-to-one correspondence between the graphical object and the code. And the you created a new graphical object (new WidgetBot, e.g.) and added it to the stage, it's class (for example event listeners, data structures, etc) was already set up to work with it.

Is this a technique that can easily be brought to the HTML/JS world? That is, does it make sense to, say, associate a DIV with a Javascript class or object? So that one could "place" this DIV on screen (by showing it via CSS or adding the HTML via jQuery) and then it would auto-magically have the event listeners associated with elements "within" that DIV be ready to go? If so, is there a specific technique for doing so?

Again, this may be a non-starter in the JS world, and if so please don't down-vote me -- it was the way to do things in the AS3 world, and it was a great way to keep code organised. I was just wondering whether any of this could be translated here.

Aucun commentaire:

Enregistrer un commentaire