Skip to content

Instantly share code, notes, and snippets.

@DavisDevelopment
Created January 8, 2015 09:23
Show Gist options
  • Save DavisDevelopment/a6e9bec81d4f1838996f to your computer and use it in GitHub Desktop.
Save DavisDevelopment/a6e9bec81d4f1838996f to your computer and use it in GitHub Desktop.
JavaScript Getter/Setter Functions
/*
--
> 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;
}
@anthonybrown
Copy link

undefined unless I invoke the function like so nameGetterSetter ("Ryan Davis") then it return's name;

"Ryan Davis"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment