diff --git a/lib/node_modules/@stdlib/array/base/zip2views/lib/main.js b/lib/node_modules/@stdlib/array/base/zip2views/lib/main.js index e78b5782b69a..19aa8ebb67a1 100644 --- a/lib/node_modules/@stdlib/array/base/zip2views/lib/main.js +++ b/lib/node_modules/@stdlib/array/base/zip2views/lib/main.js @@ -26,6 +26,71 @@ var accessors = require( '@stdlib/array/base/accessors' ); var copy = require( '@stdlib/array/base/copy' ); +// FUNCTIONS // + +/** +* Returns an accessor for returning the value associated with a label. +* +* @private +* @param {Collection} arr - input array +* @param {Function} getter - array element accessor +* @returns {Function} accessor +*/ +function getValue( arr, getter ) { + return get; + + /** + * Returns the value associated with a label. + * + * @private + * @returns {*} result + */ + function get() { + return getter( arr, this._i ); // eslint-disable-line no-invalid-this + } +} + +/** +* Returns an accessor for setting the value associated with a label. +* +* @private +* @param {Collection} arr - input array +* @param {Function} setter - array element accessor +* @returns {Function} accessor +*/ +function setValue( arr, setter ) { + return set; + + /** + * Sets the value associated with a label. + * + * @private + * @param {*} value - value to set + */ + function set( value ) { + setter( arr, this._i, value ); // eslint-disable-line no-invalid-this + } +} + +// eslint-disable-next-line stdlib/jsdoc-typedef-typos +/** +* Constructor for creating a composite view of zipped elements. +* +* ## Notes +* +* - The constructor's prototype is reset at the start of each `zip2views` invocation (see below) so that views created by one invocation never inherit label accessors defined by a different invocation. +* +* @private +* @constructor +* @param {NonNegativeInteger} i - element index +* @returns {Datum} datum instance +*/ +function Datum( i ) { + setNonEnumerableReadOnly( this, '_i', i ); + return this; +} + + // MAIN // /** @@ -102,19 +167,8 @@ function zip2views( arrays, labels ) { // Create a copy of provided labels to prevent external mutation: keys = copy( labels ); - // eslint-disable-next-line stdlib/jsdoc-typedef-typos - /** - * Constructor for creating a composite view of zipped elements. - * - * @private - * @constructor - * @param {NonNegativeInteger} i - element index - * @returns {Datum} datum instance - */ - function Datum( i ) { - setNonEnumerableReadOnly( this, '_i', i ); - return this; - } + // Reset the shared constructor's prototype so that this invocation's views only ever expose this invocation's labels: + Datum.prototype = {}; // Define read/write accessors for each label... for ( i = 0; i < M; i++ ) { @@ -132,50 +186,6 @@ function zip2views( arrays, labels ) { } return out; - /** - * Returns an accessor for returning the value associated with a label. - * - * @private - * @param {Collection} arr - input array - * @param {Function} getter - array element accessor - * @returns {Function} accessor - */ - function getValue( arr, getter ) { - return get; - - /** - * Returns the value associated with a label. - * - * @private - * @returns {*} result - */ - function get() { - return getter( arr, this._i ); // eslint-disable-line no-invalid-this - } - } - - /** - * Returns an accessor for setting the value associated with a label. - * - * @private - * @param {Collection} arr - input array - * @param {Function} setter - array element accessor - * @returns {Function} accessor - */ - function setValue( arr, setter ) { - return set; - - /** - * Sets the value associated with a label. - * - * @private - * @param {*} value - value to set - */ - function set( value ) { - setter( arr, this._i, value ); // eslint-disable-line no-invalid-this - } - } - /** * Serializes a datum to JSON. *