Created
February 18, 2015 07:01
-
-
Save zerg000000/83991792d84314dc4618 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
// 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