« Return to Thread: passing this
Re: passing this
I played with this (and was inspired by the code in
http://blog.jcoglan.com/2007/10/30/asynchronous-function-chaining-in-javascript)
and created a namespacing plugin:
(function($){
$.namespace = function(ns, functions){
$.fn[ns] = function() {return this.extend(functions)};
};
$.namespace('$', $.fn); // the default namespace
})(jQuery);
So now you can have a plugin:
$.fn.func = function(){alert('plugin'); return this'};
and create plugins in a namespace:
$.namespace ('mynamespace', {
func: function() {alert('namespaced plugin'); return this;},
otherfunc: function() {return this.css('color', 'yellow');}
});
And if you do
$('div').func(); // alerts 'plugin' -- no namespace
But
$('div').mynamespace().func(); // alerts 'namespaced plugin'
And
$('div').mynamespace().func().$().func(); // alerts 'namespaced
plugin', then resets to the normal jquery and alerts 'plugin'
Danny
On Oct 28, 5:50 pm, Jean-Sébastien <jeansebastien....@...>
wrote:
> sorry, james i didn't see someone answer me.
> what i want to do is ('div').set_of_plugins.choosen_plugin(). where
> the first level (set_of_plugins) is kind of container (namespace) of
> all my plugins. is it possible to do it?
>
> On Oct 28, 5:20 pm, James Dempster <letss...@...> wrote:
>
« Return to Thread: passing this
| Free embeddable forum powered by Nabble | Forum Help |