Created
October 4, 2010 16:49
-
-
Save benreesman/610036 to your computer and use it in GitHub Desktop.
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
map: function(object, fn) { | |
var rv = '' ; | |
// enumerate keys so that we can tell first and last | |
var keys = [] ; | |
for (k in object) keys[keys.length] = k ; | |
// invoke the block with each key/value pair (and first/last) | |
for (var i = 0 ; i < keys.length ; i++) { | |
rv += fn({ | |
k: keys[i], | |
v: object[keys[i]], | |
first: 0 == i, | |
last: (keys.length - 1 == i) | |
}) ; | |
} | |
return rv ; | |
}, | |
/* ... | |
<a href='#!{{href}}'{{#id}} id='{{.}}'{{/id}}{{#class}} class='{{.}}'{{/class}}{{#style}} style='{{.}}'{{/style}} {{#map data}}data-{{k}}='{{v}}'{{^last}} {{/last}}{{/map}}>{{content}}</a> | |
... */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment