Skip to content

Instantly share code, notes, and snippets.

@laser
Created January 9, 2012 06:01
Show Gist options
  • Save laser/1581394 to your computer and use it in GitHub Desktop.
Save laser/1581394 to your computer and use it in GitHub Desktop.
an alternative to templating languages...
<html>
<head>
<script type="text/javascript">
function PodcastPage(podcasts) {
this.podcasts = podcasts;
this.build = function(root) {
var i,
len,
header,
text;
for (i = 0, len = this.podcasts.length; i < len; i++) {
header = document.createElement("h2");
header.appendChild(document.createTextNode(this.podcasts[i].title));
text = document.createElement("p");
text.appendChild(document.createTextNode(this.podcasts[i].description));
root.appendChild(header);
root.appendChild(text);
}
}
}
document.onDomReady(function(e) {
var myPage;
myPage = new PodcastPage(<% some_podcast_json_from_server %>);
myPage.build(document.getElementById("root"));
}));
</script>
</head>
<body>
<div id="root"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment