I am basically looking for Critique on the following code as i know its not the best and i am trying to find a set way of building javascript objects.
Be brutal as you way its a learning tool for me, basically i am pulling in a twitter feed via json and adding it to the dom.
var TwitterTimeline = {
twitterFeed: function (data) {
$.ajax({
url: 'http://example.com/api/twitter/timeline/name/' + data.name,
dataType: 'json',
crossDomain: true,
cache: false,
success: function (items) {
var tweets = "<ul>";
$.each(items, function (i, tweet) {
var parser = new TwitterTimeline.Parser(tweet.text);
parser.linkifyURLs();
parser.linkifyHashTags();
tweets += "<li><h6><a href=''>" + tweet.user.name + "</a></h6>" + parser.getHTML() + "</li>";
if(i === (data.limit - 1)) {
return false;
}
});
tweets += "</ul>";
$(data.id).html(tweets);
}
});
},
Parser: function (text) {
var html = text;
var urlRegex = /((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi;
var hashTagRegex = /#([^ ]+)/gi;
this.linkifyURLs = function () {
html = html.replace(urlRegex, '<a href="$1">$1</a>');
};
this.linkifyHashTags = function () {
html = html.replace(hashTagRegex, '<a href="http://twitter.com/#!/search?q=%23$1">#$1</a>');
};
this.getHTML = function () {
return html;
};
}
}
TwitterTimeline.twitterFeed({
id: "#twitter-feed",
name: 'testaccount',
limit: 2
});
And my html
<div id="twitter-feed" class="twitter-feed"></div>
Any issues or bad practise which i bet there is a lot please let me know. So many different way to do things with javascript i always feel like i am hacking things together without any structure.
Thanks