11. Example: Underscore.js
var posts = [{
id: 1,
title: 'JavaScript is cool'
}, {
id: 2,
title: 'The Web is the platform'
}];
_.pluck(posts, 'title');
// ['JavaScript is cool', 'The Web is the platform']
20. Example: Handlebars.js
var template =
'<ul>'
'{{#each posts}}'
' <li>{{title}}</li>'
'{{/each}}'
'</ul>'
;
var templateFn = Handlebars.compile(template)
, html = templateFn({posts: posts});
// <ul>
//
<li>JavaScript is cool</li>
//
<li>The Web is the platform</li>
// </ul>
21. Shimmed per environment
Provides shims for accessing
environment-specific properties so
module can expose a single API.
window.location.pathname
vs.
req.path
35. Browserif
Package up CommonJS modules
for the browser.
Use ‘require()’ in the browser, the
same way you would on the server.
36. Browserif
// app/template_renderer.js
var handlebars = require('handlebars');
module.exports = function(templatePath, data) {
var templateFn = require('./views/' + templatePath)
, html = templateFn(data);
return html;
};
Bundles a module and all its dependencies.