Nice post! It's interesting that hardly anyone has chimed in that some programming language features make addressing this problem considerably simpler without forcing the programmer to write excess boilerplate. Objective-C delegation, JavaScript Proxies https://developer.mozilla.org/en/JavaScript/Reference/Global..., ClojureScript protocols all provide the machinery to make this kind of thing work without making the code too hard to reason about.
However, I think that sprinkling andro.eventer all over the place is a stumbling block to me - it's essentially a global variable.
I realise that you don't want to polute the objects too much, but why not just add bind and emit methods to the composed object? Either that or pass andro as a parameter to the mixin's setup method?
Also, the bind(this, "touch", function...) to me looks like you're binding to the "touch" event of "this". Is the closure tax really so high that you can't store "this", or use something like jQuery.proxy()?
Like I said, I think this approach has a lot of potential, and seems to fit quite naturally the eventful model that the DOM uses.
Yes, andro.eventer is there to avoid polluting the owner object. However, your idea of passing andro to the behaviour's setup() method is a great one. I'm going to give it a try.
The reason I require the behaviour to be passed to bind() is so that the passed function can be run with `this` set to the behaviour. I couldn't see another way to let bind know which behaviour should be bound to the event.
[+] [-] swannodette|14 years ago|reply
[+] [-] david_a_r_kemp|14 years ago|reply
However, I think that sprinkling andro.eventer all over the place is a stumbling block to me - it's essentially a global variable.
I realise that you don't want to polute the objects too much, but why not just add bind and emit methods to the composed object? Either that or pass andro as a parameter to the mixin's setup method?
Also, the bind(this, "touch", function...) to me looks like you're binding to the "touch" event of "this". Is the closure tax really so high that you can't store "this", or use something like jQuery.proxy()?
Like I said, I think this approach has a lot of potential, and seems to fit quite naturally the eventful model that the DOM uses.
[+] [-] maryrosecook|14 years ago|reply
Yes, andro.eventer is there to avoid polluting the owner object. However, your idea of passing andro to the behaviour's setup() method is a great one. I'm going to give it a try.
The reason I require the behaviour to be passed to bind() is so that the passed function can be run with `this` set to the behaviour. I couldn't see another way to let bind know which behaviour should be bound to the event.
[+] [-] jcromartie|14 years ago|reply
[+] [-] revelation|14 years ago|reply
[+] [-] maryrosecook|14 years ago|reply
[+] [-] peter_l_downs|14 years ago|reply