Skip to content

Instantly share code, notes, and snippets.

@nitinsurana
Created November 29, 2014 05:10
Show Gist options
  • Save nitinsurana/2eaeb7c0b25a4a5d3376 to your computer and use it in GitHub Desktop.
Save nitinsurana/2eaeb7c0b25a4a5d3376 to your computer and use it in GitHub Desktop.
<script>
namespace = {abc:{person:{}}}
namespace.abc.common = function() {
var arr = [];
var setArr = function(v) {
if (v) {
arr.push(v);
}
}
var getArr = function() {
return arr;
}
var registerArr = function(ns) {
if (ns) {
for (var obj in ns) {
if (obj.hasOwnProperty("getName")) {
setArr(obj.getName());
}
}
}
}
return {
setArr: setArr,
getArr: getArr,
registerArr: registerArr
}
}
namespace.abc.form = function() {
var salutation = "Hi";
var name = '';
var getSalutation = function() {
return salutation;
}
var getName = function() {
return name;
}
var setSalutation = function(s) {
salutation = s;
}
var setName = function(n) {
name = n;
}
return {
getSalutation: getSalutation,
setSalutation: setSalutation,
getName: getName,
setName: setName
}
}
person = namespace.abc.person;
person.Dave = new namespace.abc.form();
person.Dave.setName("Dave");
person.Mitchell = new namespace.abc.form();
person.Mitchell.setName('Mitchell');
person.Mitchell.setSalutation('Howdy');
console.log(person.Mitchell.getSalutation());
console.log(person.Mitchell.hasOwnProperty('getName'));
commonObj = new namespace.abc.common();
commonObj.registerArr(person);
document.getElementById('result').innerHTML = commonObj.getArr();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment