Created
November 29, 2014 05:10
-
-
Save nitinsurana/2eaeb7c0b25a4a5d3376 to your computer and use it in GitHub Desktop.
This file contains 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
<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