Created
March 10, 2015 17:52
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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()); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Working Fiddle to Demo: http://jsfiddle.net/kdarty/F3gPZ/1/