Skip to content

Instantly share code, notes, and snippets.

@benreesman
Created October 4, 2010 16:49
Show Gist options
  • Save benreesman/610036 to your computer and use it in GitHub Desktop.
Save benreesman/610036 to your computer and use it in GitHub Desktop.
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