Plugin callback functions: Return $(this) or this?
Hi,
In my plugin, I wrote a private method to handle callbacks:
- function _call_back($_fun, $_obj) {
-
- if ($.isFunction($_fun)) {
- $_fun.call($_obj);
- }
-
- };
In the guts of my plugin, there are times where I have easy access to "this":
- $foo.animate(..., function(){
- _call_back(settings.callback1, this);
- });
But, there are other situations where $(this) is easier to return:
- $foo = $var.filter(':eq(' + index + ')');
- _call_back(settings.callback2, $foo);
When it comes to coding, I tend to like consistency, and don't like surprises... With that said, should I be returning the object lookup for all of my callbacks, or just the "this"?
For example, if I were to return "this" in my last example, I was thinking this would work:
- _call_back(settings.callback2, $foo[0]);
What do ya'll think?
Many TIA!
Cheers,
Micky