Created
January 6, 2013 12:58
-
-
Save vstarck/4466946 to your computer and use it in GitHub Desktop.
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
var person = (function() { | |
var name, lastname; | |
function get(key) { | |
switch(key) { | |
case 'name': return name; break; | |
case 'lastname': return lastname; break; | |
default: return null | |
} | |
} | |
function set(key, value) { | |
switch(key) { | |
case 'name': name = value; return name; break; | |
case 'lastname': lastname = value; return lastname; break; | |
default: return null | |
} | |
} | |
return function(method, args) { | |
args = args || []; | |
if(method == 'get') { | |
return get(args[0]); | |
} | |
if(method == 'set') { | |
return set(args[0], args[1]); | |
} | |
} | |
})() | |
console.log('GET name ', person('get', ['name'])); | |
console.log('SET name ', person('set', ['name', 'Joe'])); | |
console.log('GET name ', person('get', ['name'])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment