Skip to content

Instantly share code, notes, and snippets.

@pauliusuza
Created November 1, 2012 17:11
Show Gist options
  • Save pauliusuza/3995097 to your computer and use it in GitHub Desktop.
Save pauliusuza/3995097 to your computer and use it in GitHub Desktop.
Javascript Class
/*jshint browser:true, jquery:true, undef:true, devel:true, unused:false, curly:true, strict:true,
noarg:true, noempty:true, eqeqeq:true, bitwise:true, quotmark:true, indent:2, maxerr:50 */
/*global window:true */
/**
Global Class collection with a class(klass) object with private and public variables/methods without using this.
@author John Doe
@namespace classLib
*/
(function (window) {
'use strict';
var classLib = window.classLib || {};
/**
@class klass
@namespace classLib
*/
classLib.klass = function () {
/* Private variables */
var _foo, _bar;
_foo = 'foo';
_bar = 'bar';
/*-------------------------------------------------------*/
/* Private functions */
var _privateFunc = function () {
_foo = _bar;
};
return {
/* Public functions */
init: function () {
privateFunc();
},
getFoo: function () {
return _foo;
},
setFoo: function (value) {
_foo = value || _foo;
}
};
}();
// Expose klass to the global object
window.classLib = classLib;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment