Skip to content

Instantly share code, notes, and snippets.

@kdarty
Created March 10, 2015 17:52
Show Gist options
  • Save kdarty/132f52a5401649be002a to your computer and use it in GitHub Desktop.
Save kdarty/132f52a5401649be002a to your computer and use it in GitHub Desktop.
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());
});
@kdarty
Copy link
Author

kdarty commented Mar 10, 2015

Working Fiddle to Demo: http://jsfiddle.net/kdarty/F3gPZ/1/

@kdarty
Copy link
Author

kdarty commented Mar 10, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment