Use invoke to change properties on each model in Backbone collection

Posted by Jason Merino on July 3, 2014

Here’s a quick tip. If you need to set the same property on each model in a Backbone collection check out the following snippet.

this.collectionName.invoke('set', {
	isSet: true
});

Invoke can be used as a slightly cleaner version of this.

this.collectionName.each(function(model) {
	model.set({
		isSet: true
	});
});

Happy coding!


jason merino

Jason Merino

Jason is a software engineer specializing in JavaScript and web technologies. An avid gardener, aspiring carpenter and a blessed family man.