Skip to content

Instantly share code, notes, and snippets.

@heymichaelp
Last active August 29, 2015 14:04
Show Gist options
  • Save heymichaelp/c7465add51643edaf4bd to your computer and use it in GitHub Desktop.
Save heymichaelp/c7465add51643edaf4bd to your computer and use it in GitHub Desktop.
Decorators: Example Service Object
var _ = require('underscore')
var GenerateReportCard = function(student) {
this.student = student
};
GenerateReportCard.prototype = _.extend(GenerateReportCard.prototype, {
run: function() {
return _.compose(
this.saveReportCardAsPDF,
this.generateReportCardHtml,
this.getStudentGrade
).call(this)
},
getStudentGrade: function() {
// some actions here to
// determine grade
return grade
},
generateReportCardHtml: function(grade) {
// some actions here to
// build html for report card
return html
},
saveReportCardAsPDF: function(html) {
// some actions here to
// save PDF and get the url
return pdfUrl
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment