Is this a good way to create a class with a constructor and namespace in object literal style?
// root namespace
var myApp = myApp || {};
// sub namespace
myApp.model = {
// Constructor
Person: function (name) {
this.name = name;
}
};
myApp.model.Person.prototype = {
sayName: function () {
alert(this.name);
},
sayHi: function () {
alert("Hi, " + this.name);
}
};
var p1 = new myApp.model.Person("CK");
p1.sayName();
p1.sayHi();
JSHint shows no error and the full source code is at http://jsfiddle.net/cklee75/vj4ujz0L/2/here.