Created
April 20, 2012 10:25
-
-
Save oslego/2427644 to your computer and use it in GitHub Desktop.
Templates in JavaScript using Array
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
/* | |
Neat alternative to JavaScript templating by using an array. | |
Inspired by Ryan Florence | |
https://github.com/rpflorence/snack/blob/master/demos/jsonp/demo.js | |
*/ | |
var h = [], | |
p = function (){ h.push.apply(h, arguments) }, | |
data = ["one", "two", "three"] | |
// who needs templates when you have arrays?! :P | |
p('<ul>') | |
data.forEach(function(item){ | |
p('<li>' + item + '</li>') | |
}) | |
p('</ul>') | |
document.body.innerHTML = h.join('') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment