Skip to content

Instantly share code, notes, and snippets.

@zerg000000
Created February 18, 2015 07:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zerg000000/83991792d84314dc4618 to your computer and use it in GitHub Desktop.
Save zerg000000/83991792d84314dc4618 to your computer and use it in GitHub Desktop.
// Parameter Object opts instead of withQuot and withComma
function trickyToString(data, opts) {
//trickyToString become a Template method
// quot and comma flag become Strategy of trickyToString method
var quotFunc = opts.withQuot || function(s){ return s; };
var commaFunc = opts.withComma || function(){ return ","; };
var outStr = "";
for( key in data ) {
outStr = outStr + quotFunc(key) + commaFunc() + quotFunc(data[key]) + "\n";
}
return outStr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment