Created
January 8, 2015 09:23
-
-
Save DavisDevelopment/a6e9bec81d4f1838996f to your computer and use it in GitHub Desktop.
JavaScript Getter/Setter Functions
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
/* | |
-- | |
> SUPER SIMPLE example of a GetterSetter function which operates on a normal variable | |
-- | |
*/ | |
//- The Variable the GetterSetter will be operating on | |
var name = "Ryan Davis"; | |
/** | |
* The GetterSetter for [name] | |
* --- | |
* @param optional new_name - if provided, [name] will be reassigned to this | |
* @returns [name] | |
*/ | |
function nameGetterSetter( new_name ) { | |
if (new_name != null) { | |
name = new_name; | |
} | |
return name; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
undefined
unless I invoke the function like sonameGetterSetter ("Ryan Davis")
then it return'sname
;"Ryan Davis"