Published in: JavaScript
this snippet will help you understand how to use namespacing and oop construnction in JavaScript
// namespaced constructor object var NAMESPACED_CONSTRUCTOR = function (){ var _privateVar = 'NAMESPACED_CONSTRUCTOR'; var _privateMethod = function (subparam){ this.paramValue = subparam; alert(this.paramValue + ' instance of ' + _privateVar + ' created '); }; _privateMethod.prototype.showValue = function (){ alert(_privateVar + ', this object´s value is : ' + this.paramValue); }; // public instanciable items var _public = { Instance : _privateMethod }; alert(_privateVar + ' created'); return _public; }(); window.onload = function (){ var oNAMESPACED_CONSTRUCTOR = new NAMESPACED_CONSTRUCTOR.Instance('ok2'); oNAMESPACED_CONSTRUCTOR.showValue(); }
You need to login to post a comment.
