Say you have some html document that has some elements with assigned IDs. I would like to find better notation for functions – event handlers in TIScript.
For example we have following html fragment:
<button id="foo">Click me!</button>
and we know that such button can generate onClick event (whatever it means).
There are multiple possible ways of how to do this in JavaScript. First of all standard way (that uses function $() – get element by selector)
$("#foo").onClick = function() { ... }
This means: assign anonymous function (handler) to onClick property (event name) so system will call back that function when event will happen.
Internet Explorer (JScript) allows to do the same definition as:
function foo::onClick() { ... } // or probably this way: function foo.onClick() { ... } // and in VBScipt sub foo_onClick() ... end sub
This is possible in IE because all elements that have IDs are seen as variables of global name space. That approach has some limitations: IDs in HTML can contain characters that are not valid in variable names, e.g. ‘-‘ in #foo-bar.
Sciter/TIScript has symbols that allowed to use ‘-‘ and all other characters allowed in IDs (html/xml):
// for element with id="foo" function self#foo.onClick() { ... } // for element with id="foo-bar" function self#foo-bar.onClick() { ... }
self#foo-bar
is a syntax sugar – equivalent of self["#foo-bar"]
Syntax is a bit “noisy” but works. Other variants that I’ve considered:
function onClick of self#foo (...) { ... } when onClick on self#foo-bar (...) { ... }
and other variations. I don’t really know what is better… Any ideas?