I'm looking for a barebones javascript example that demonstrates how the javascript plugin architecture works with large javascript libraries (such as raphael or jquery). In either scenario, you build plugins by ensuring your custom plugin follows this pattern: jQuery.fn.pluginName
-- so assume I have a library:
myLibrary = (function() {
//my fancy javascript code
return function() {
//my return object
};
});
How would fn
be incorporated into the above myLibrary
object to ensure that he resulting plugin is callable? I instantiate myLibrary
like so:
var lib = new myLibrary();
And now I have included a reference to my plugin in my page:
myLibrary.fn.simplePlugin = function() { //more fancy code }
So finally, I can just call:
lib.simplePlugin();
Basically, what magic is actually occuring when the .fn
is used during the creation of the plugin?