function MyPlugin(inputNodes, options) { this.options = options; // In this example, let's say we need to do something special with the first // inputNode as compared to the others. [this.firstNode, ...this.otherNodes] = inputNodes; this.firstNode.appendChildNode(this.options.startCallback); // pre-firstNode hook this.wrapChildNode(0, this.options.secondCallback); // post-firstNode hook // Callback after every "otherNode" this.otherNodes.forEach((n, i) => this.wrapChildNode(i + 1, this.options.postEachOtherCallback)); // Make `finalCallback` only get called after _all_ input nodes are fully finished // using the little eventComposeHelper util (included below). A bit superficial // but illustates needing to "hook" into the completion of X different nodes this.appendChildNode(this.options.finalCallback); Plugin.call(inputNodes, options); } MyPlugin.prototype.build = function() { // Whatever else this plugin wants to do in its build ... }