Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #30684
| From | "Chris M. Thomasson" <nospam@nospam.invalid> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Object Oriented Elements, callbacks... |
| Date | 2016-06-18 14:56 -0700 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <nk4g26$13la$1@gioia.aioe.org> (permalink) |
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! :^)
Back to comp.lang.javascript | Previous | Next — Next in thread | Find similar | Unroll thread
Object Oriented Elements, callbacks... "Chris M. Thomasson" <nospam@nospam.invalid> - 2016-06-18 14:56 -0700
Re: Object Oriented Elements, callbacks... "Chris M. Thomasson" <nospam@nospam.invalid> - 2016-06-18 15:03 -0700
Re: Object Oriented Elements, callbacks... "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-06-18 15:12 -0700
Re: Object Oriented Elements, callbacks... "Chris M. Thomasson" <nospam@nospam.invalid> - 2016-06-18 15:12 -0700
Re: Object Oriented Elements, callbacks... "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-06-18 15:19 -0700
Re: Object Oriented Elements, callbacks... "Chris M. Thomasson" <nospam@nospam.invalid> - 2016-06-19 01:06 -0700
Re: Object Oriented Elements, callbacks... "Chris M. Thomasson" <nospam@nospam.invalid> - 2016-06-19 12:06 -0700
Re: Object Oriented Elements, callbacks... "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-06-19 12:27 -0700
csiph-web