Skip to content

Instantly share code, notes, and snippets.

@glauberramos
Created July 19, 2012 03:03
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 glauberramos/3140489 to your computer and use it in GitHub Desktop.
Save glauberramos/3140489 to your computer and use it in GitHub Desktop.
Bad javascript code - Example for blog post - DRY
function book(name, author, content, date) {
var name = name;
var author = author;
var content = content;
var date = date;
var self = {
containsWord: function(word) {
return content.indexOf(word) >= 0;
},
removeWord: function(word) {
return self.containsWord(word) ? content.replace(word + ' ', '') : content;
},
replaceWord: function(oldWord, newWord) {
return self.containsWord(word) ? content.replace(oldWord, newWord) : content;
},
getName: function() { return name; },
getAuthor: function() { return author; },
getContent: function() { return content; },
getDate: function() { return date; }
};
return self;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment