Just wondering what you all think of the way I am hooking up DOM
elements, buttons for now, to objects via callbacks. Here is an example
page:
http://funwithfractals.atspace.cc/ct_root/ct_ui
The code can be found here:
http://funwithfractals.atspace.cc/ct_root/ct_ui/ct_main.js
I am dynamically attaching an object to a button element with bind in
the following functions (ct_ui_button_obj, ct_ui_button_factory):
// Abstract button object
//_________________________________________________________
function ct_ui_button_obj(e, s)
{
this.m_e = e;
this.m_s = s;
}
// Abstract button factory
//_________________________________________________________
function ct_ui_button_factory(eid, ftor_onclick, state)
{
var e = document.getElementById(eid);
if (! e) return null;
var obj = new ct_ui_button_obj(e, state);
if (! obj) return null;
obj.m_e.addEventListener("click", ftor_onclick.bind(obj));
return obj;
}
called like:
_____________________________
function main_button_test()
{
g_button = ct_ui_button_factory("g_html_button", my_on_click, [0,
1, 2, 3]);
if (! g_button) throw "ID Parse Error";
}
_____________________________
Does this look Kosher to you?
<program entry is main, which is called from body onload event...>
__________________________________________
"use strict";
// Abstract button object
//_________________________________________________________
function ct_ui_button_obj(e, s)
{
this.m_e = e;
this.m_s = s;
}
// Abstract button factory
//_________________________________________________________
function ct_ui_button_factory(eid, ftor_onclick, state)
{
var e = document.getElementById(eid);
if (!e) return null;
var obj = new ct_ui_button_obj(e, state);
if (!obj) return null;
obj.m_e.addEventListener("click", ftor_onclick.bind(obj));
return obj;
}
// Test App for hooking up existing DOM to OO buttons...
//_________________________________________________________
var g_button = null;
function my_on_click()
{
alert("my_on_click::m_s = " + this.m_s);
}
function main_button_test()
{
g_button = ct_ui_button_factory("g_html_button", my_on_click, [0,
1, 2, 3]);
if (! g_button) throw "ID Parse Error";
}
// called from <body onload="main();">
function main()
{
try
{
main_button_test();
}
catch (e)
{
alert(e);
}
}
__________________________________________
Thanks! :^)