Basic Namespace Example in JavaScript. (FYI: This dates back to a Google+ Discussion from 2011)
"use strict";
var ACME = {};
ACME.Web = {};
ACME.Web.UI = {};
ACME.Web.UI.Customer = function () {
var FirstName, LastName, FullName;
FullName = function () {
return this.FirstName + " " + this.LastName;
}
return {
FirstName: FirstName,
LastName: LastName,
FullName: FullName
};
};
// Test Method (where 'testScript' is an HTML Object such as a Button)
$("#testScript").click(function () {
var customer = new ACME.Web.UI.Customer();
customer.FirstName = "John";
customer.LastName = "Smith";
alert(customer.FullName());
});