Skip to main content

Function Structure with Namespace jQuery Template

By Sam Deering



Free JavaScript Book!

Write powerful, clean and maintainable JavaScript.

RRP $11.95

Hi guys, thought I would share with you the template i use to structure some code when writing a new jQuery function inside the JQUERY4U.POSTS namespace. Not every function (or plugins for that matter) are coded the same way, that’s a fact. But looking at templates is a good way to learn to write efficient code.

* Function Name
* Function Description
* @author          
* @modifiedby      
* @copyright       
* @version         
* @lastmodified    
* @requires

    name: 'JQUERY4U.POSTS',
	//variables available to whole of namespace
	postIds: [],
    init: function($, opts)
        if(typeof opts!='undefined')
            $.extend(this.options, opts); 
            // check if IE 6 (use a mix of feature detection and the version string).
            if(!($.support.cssFloat) && ($.browser.version).charAt(0) == '6'){
            // preload the CSS background
            preloadImage = new Image(); 
            preloadImage.src = "/fcweb/searchpanel/images/autocompleteBg.gif";
	setupPostLayout: function(){
	setupPostOptions: function(){
	setupPostText: function(){
	setupPostImage: function(){
	//example call to options

Related Articles

Sam Deering has 15+ years of programming and website development experience. He was a website consultant at Console, ABC News, Flight Centre, Sapient Nitro, and the QLD Government and runs a tech blog with over 1 million views per month. Currently, Sam is the Founder of Crypto News, Australia.

New books out now!

Learn the basics of programming with the web's most popular language - JavaScript

A practical guide to leading radical innovation and growth.

Integromat Tower Ad