Created
July 19, 2012 02:37
-
-
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 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
//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