Skip to content

Instantly share code, notes, and snippets.

@lymanlai
Created November 14, 2012 13:46
Show Gist options
  • Save lymanlai/4072168 to your computer and use it in GitHub Desktop.
Save lymanlai/4072168 to your computer and use it in GitHub Desktop.
jQuery plugin pattern
<!doctype html>
<html lang="en">
<head>
<title>JavaScript Patterns</title>
<meta charset="utf-8">
</head>
<body>
<script>
/*!
* jQuery extend-based plugin boilerplate
* https://github.com/shichuan/javascript-patterns/blob/master/jquery-plugin-patterns/extend.html
* Author: @oscargodson
* Further changes: @timmywil
* Licensed under the MIT license
*/
/*
As you'll notice below, we're making use of $.fn.extend to create our plugin rather
than opting for $.fn.pluginname. This type of structure may be useful if you need
to add a relatively large number of methods to your plugin. There are however alternatives
to this that may be better suited, including Alex Sexton's prototypal inheritence pattern
which is also included in this repo.
*/
// the semi colon before function invocation is a safety net against concatenated
// scripts and/or other plugins which may not be closed properly.
;( function( $ ){
$.fn.extend( {
pluginname: function( options ) {
this.defaults = {};
var settings = $.extend( {}, this.defaults, options );
return this.each( function() {
var $this = $( this );
});
}
});
})( jQuery );
// References
// Essential jQuery Plugin Patterns (by Addy Osmani) - http://goo.gl/oE0ge
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment