Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var o = {}; /* namespace */
- (function(undefined) {
- this.trimPeriods = function(s) {
- var return_string; /* private to trimPeriods() */
- (function killCrushDestroy(s) { /* a non-polluting-recursive-function (that trims periods from the end of a string) */
- if (s.substr(s.length - 1, 1) == ".") {
- killCrushDestroy(s.substring(0, s.length - 1));
- } else {
- return_string = s; /* if we did a return here, we wouldn't be returning to the original caller */
- }
- })(s); /* pass the arg sent to trimPeriods() into killCrushDestroy() */
- return return_string; /* send return string back to whoever called us */
- };
- }).apply(o); /* apply everything in here to the "o" object */
- alert(o.trimPeriods("blah...")); /* alerts "blah" */
Add Comment
Please, Sign In to add comment