Two popular patterns for configuration in JavaScript are the builder pattern and the options object pattern:
Builder
var importer = new LeadImporter()
.assignLeads(true)
.source("source")
.organization(organization)
.setLeads(leads)
importer.processP().then(function() {
...
})
Options Object
var importer = new LeadImporter({
assignLeads: true,
source: "source",
organization: organization
})
importer.processP(leads).then(function() {
...
})
I'm trying to decide which to use for the design of a contact importer.
My gut is that the options object pattern is a better fit because the importer is configured up front and not piecemeal or over time (for which the builder would be better suited), but I want to do whatever is more idiomatic javascript for this particular usage.
Additionally, I believe the leads should be provided as an argument to processP() instead of set on the importer object so that the importer can be re-used on multiple sets of leads. Does that make sense?
Aucun commentaire:
Enregistrer un commentaire