Coding Patterns

This website contains links to software which is either no longer maintained or will be supported only until the end of 2019 (CKFinder 2). For the latest documentation about current CKSource projects, including software like CKEditor 4/CKEditor 5, CKFinder 3, Cloud Services, Letters, Accessibility Checker, please visit the new documentation website.

If you look for an information about very old versions of CKEditor, FCKeditor and CKFinder check also the CKEditor forum, which was closed in 2015. If not, please head to StackOverflow for support.

This page lists some interesting coding patterns that we may or may not use in our code.

Self Executing Functions

This is already a classic. Using a self calling function declaration to isolate its contents from the current scope, avoiding polluting it with variables.

(function()
{ 
	... 
})();

Objects with Private Stuff

var myObj = function()
{ 
	// Private variables.
	var privateVar = 10;

	var privateFunction = function()
	{ 
        ... 
	};

	// Public stuff.
	return { 
      	publicMethod : function()
		{ 
			// May access privateVar or privateFunction.
        		... 
		}
	};
}();

For Loops and Length

The "length" property should not be checked on each "for" cycle. The following construction should be used instead:

 
for ( var i = 0, len = list.length ; i < len ; i++ } 
{ 
        ... 
} 
This page was last edited on 13 September 2010, at 15:44.