MCPcopy Create free account
hub / github.com/cryptii/cryptii / create

Method create

src/Factory.js:70–82  ·  view source on GitHub ↗

* Creates a new instance by given identifier. * @param {string} identifier * @param {...mixed} args Arguments passed to the invokable constructor * @return {object} Instantiated object

(identifier, ...args)

Source from the content-addressed store, hash-verified

68 * @return {object} Instantiated object
69 */
70 create (identifier, ...args) {
71 if (!this.exists(identifier)) {
72 throw new Error(
73 `Can't create '${identifier}', invokable has not been registered.`)
74 }
75
76 const index = this._identifiers.indexOf(identifier)
77 const invokable = this._invokables[index]
78
79 // the following lines do basically this: new invokable(...args)
80 args.splice(0, 0, invokable)
81 return new (Function.prototype.bind.apply(invokable, args))()
82 }
83
84 /**
85 * Returns factory singleton instance.

Callers 5

Factory.jsFile · 0.45
viewAddButtonDidClickMethod · 0.45
extractMethod · 0.45
addFieldMethod · 0.45

Calls 2

existsMethod · 0.95
indexOfMethod · 0.80

Tested by

no test coverage detected