Guest User

Untitled

a guest
Jan 22nd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. var o = {}; /* namespace */
  2.  
  3. (function(undefined) {
  4.  
  5. this.trimPeriods = function(s) {
  6. var return_string; /* private to trimPeriods() */
  7.  
  8. (function killCrushDestroy(s) { /* a non-polluting-recursive-function (that trims periods from the end of a string) */
  9. if (s.substr(s.length - 1, 1) == ".") {
  10. killCrushDestroy(s.substring(0, s.length - 1));
  11. } else {
  12. return_string = s; /* if we did a return here, we wouldn't be returning to the original caller */
  13. }
  14. })(s); /* pass the arg sent to trimPeriods() into killCrushDestroy() */
  15.  
  16. return return_string; /* send return string back to whoever called us */
  17.  
  18. };
  19.  
  20. }).apply(o); /* apply everything in here to the "o" object */
  21.  
  22. alert(o.trimPeriods("blah...")); /* alerts "blah" */
Add Comment
Please, Sign In to add comment