Skip to content

Instantly share code, notes, and snippets.

@glauberramos
Created July 19, 2012 02:37
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/3140395 to your computer and use it in GitHub Desktop.
Save glauberramos/3140395 to your computer and use it in GitHub Desktop.
Bad javascript code - Example for blog post - Meanful and Concise Variables/Methods Names
//this function represents a book from an online library
//it has 3 methods to search the book, remove a specific word and change it
//it has 4 attributes, name, author, date and content
//creates libaries stuffz
function book(name,author,content,date) {
var name = name;
var author = author;
var content = content;
var date = date;
var self = {
findWord: function(word) {
return content.indexOf(word)>=0;
},
removeWord: function(word) {
return content.indexOf(word)>=0?content.replace(word + ' ',''):content;
},
replaceWord: function(oldWord,newWord) {
return content.indexOf(oldWord)>=0?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