JavaScript class encaptulation

My favorite JavaScript class structure –

(function(exports) {
	"use strict";
	var mySuperDupparClassOfSHKR=function(pValue){
	var myPrivateValue;
	this.setValue=function(pValue){
		myPrivateValue=pValue;
		return this;
	};
	var __construct = function(that, pValue) {
		return that.setValue(pValue);
		}(this, pValue);
	};
	exports.SuperDupparClass = {
		create : function(pValue) {
			if(typeof pValue==='undefined') throw 'please provide a value, unable to continue...';
			return new mySuperDupparClassOfSHKR(pValue);
		},
	};
})(this);

Usage as follows –

var myObj;
jQuery(document).ready(function($) {
	try{
		myObj=SuperDupparClass.create('any value');
	}catch(e){
		alert('ERR: '+e);
	}
});

 

Posted in javascript, study, webdevelopmentTagged , , ,