I'm trying to create a module in JavaScript. I want my module to have something like a class. I'm not sure if what I"m trying is possible. Essentially, I want to be able to do this in JavaScript:
var myObject = new myCompany.myLibrary.myClass();
myObject.myFunction();
Currently, I'm trying the following:
var myCompany = myCompany || {};
myCompany.myLibrary = (function() {
var myProperty = null;
var anotherProperty = 'Hello';
return {
myClass: function () {
return {
myFunction : function() {
console.log(anotherProperty);
}
};
}
};
})();
When I do this, I get an error that says "undefined is not a function". Is it possible to do what I'm trying to accomplish in JavaScript? If so, what am I doing wrong?