Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #30691

Re: Object Oriented Elements, callbacks...

Path csiph.com!aioe.org!.POSTED!not-for-mail
From "Chris M. Thomasson" <nospam@nospam.invalid>
Newsgroups comp.lang.javascript
Subject Re: Object Oriented Elements, callbacks...
Date Sun, 19 Jun 2016 01:06:54 -0700
Organization Aioe.org NNTP Server
Lines 22
Message-ID <nk5jr2$bel$1@gioia.aioe.org> (permalink)
References <nk4g26$13la$1@gioia.aioe.org> <b6084978-53a5-4daf-bcf2-ddd910acafe8@googlegroups.com>
NNTP-Posting-Host R6BHhbAE5DPmXqvJVxAkuQ.user.gioia.aioe.org
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
X-Complaints-To abuse@aioe.org
User-Agent Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.1.1
X-Notice Filtered by postfilter v. 0.8.2
Xref csiph.com comp.lang.javascript:30691

Show key headers only | View raw


On 6/18/2016 3:19 PM, Michael Haufe (TNO) wrote:
> On Saturday, June 18, 2016 at 4:56:31 PM UTC-5, Chris M. Thomasson wrote:
>> Just wondering what you all think of the way I am hooking up DOM
>> elements, buttons for now, to objects via callbacks. [...]
>
> Try using handleEvent method instead on the prototype:
>
> function MyButton(el){
>   this.el = el
>   el.addEventListener('click', this)
> }
> MyButton.prototype = {
>   handleEvent: function(e){ this['on' + e.type](e) },
>   onclick: function(e){
>     alert("Hello World")
>   }
> }
>
> var foo = new MyButton(document.getElementById('g_html_button'))
>

This works like a charm! Thanks. :^)

Back to comp.lang.javascript | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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