At the mean time, event handler assignment…

Sciter supports event handler assignment in jQuery style:

element.on("event", "selector", function(evt) {...});

That looks mostly OK but for some reason I feel it as “aesthetically non pleasant” so thinking about alternatives.

One feasible option/idea may look like this:

// subscribe function for "click" event on element
element << function "click" (evt) {...};

That above is a direct equivalent of

element.on("click", function (evt) {...});

And in full form, with selector

// subscribe function for "click" event on <button id=first> element
self << function ["click","button#first"] (evt) {...};

The main challenge here is to stay in constraints of JS syntax/grammar …

Comments (5)

    1. ‘:’ is not required there I think. I can introduce event [... on] keyword for that matter.

      So to have

      element << event click(evt) on button#first { ... };

      There is also a desire to have event matching part:

      element << event keydown(evt) like { keyCode: Event.VK_ESCAPE } on button#first { ... };

      this will invoke the function on keydown/VK_ESCAPE on button#first. Too ugly probably 🙂

    2. BTW: if to go with event keyword then it will be possible to extend behavior classes:

      class Toggler : Behavior {
           function attached() { ... }
           event click(evt) on button#first { ... }
           event click(evt) on button#second { ... }
      }

      There is definitely something in it…

        1. Unfortunately ‘event’ cannot be used as a keyword for the legacy code support reasons.

          The only reasonable option I see is to use function "string" constructs for designating event handlers:

          element << function "click" (evt)  { ... };
          element << function "click button#first" (evt)  { ... };

          and

          class Toggler : Behavior {
               function attached() { ... }
               function "click button#first" (evt) { ... }
               function "click button#second" (evt)  { ... }
          }

Leave a Reply