klenwell information services : JavascriptStyleGuide

Revision [2757]

This is an old revision of JavascriptStyleGuide made by KlenwellAdmin on 2014-06-15 22:08:59.
 

JavaScript Style Guide


Augment Pattern

Object-oriented classes requiring classical inheritance should use the augment pattern.

Module Pattern

Modules should use the jQuery module pattern:
var BrowserCache = (function() {
  var ENGINE = localStorage;

  var setValue = function(key, value) {
	var jsonValue = JSON.stringify(value);
	ENGINE.setItem(key, jsonValue);
  };

  var getValue = function(key) {
	return JSON.parse(ENGINE.getItem(key));
  };

  // Public API
  var publicAPI = {
	set: setValue,
	get: getValue
  }

  return publicAPI;
})();