Skip to content

Instantly share code, notes, and snippets.

@sudodo
Created January 21, 2012 06:22
Show Gist options
  • Save sudodo/1651686 to your computer and use it in GitHub Desktop.
Save sudodo/1651686 to your computer and use it in GitHub Desktop.
JavaScript constructor module pattern skelton
MYAPP.namespace('MYAPP.utilities.Array');
MYAPP.utilities.Array = (function () {
// dependencies
var uobj = MYAPP.utilities.object,
ulang = MYAPP.utilities.lang;
// private properties and methods...
var Constr;
// end var
// optionally one-time init procedures
// ...
// public API -- constructor
Constr = function (o) {
this.elements = this.toArray(o);
};
// public API -- prototype
Constr.prototype = {
constructor: MYAPP.utilities.Array, version: "2.0",
toArray: function (obj) {
for (var i = 0, a = [], len = obj.length; i < len; i += 1) {
a[i] = obj[i]; }
return a; }
};
// return the constructor
// to be assigned to the new namespace
return Constr;
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment