Creating a jQuery Plugin, How do I do Custom Scopes?
- by viatropos
I would like to create a jQuery plugin with an API something like this:
$("#chart").pluginName().attr("my_attr");
Instead of these:
$("#chart").pluginName_attr("my_attr");
$.pluginName.attr("#chart", "my_attr");
Basically, instead of having to namespace every method that acts similar to ones in jQuery, I'd like to "scope" the methods to a custom api, where $("#chart).pluginName() would return an object such that get, attr, find, and a few others would be completely rewritten.
I'm sure this is not a well-liked idea as it breaks convention (does it?), but it's easier and more readable, and probably more optimized, than the two options above. What are your thoughts?