Created
November 14, 2012 13:46
-
-
Save lymanlai/4072168 to your computer and use it in GitHub Desktop.
jQuery plugin pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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