define
优质
小牛编辑
143浏览
2023-12-01
Create a new constructor function for a type inheriting from ArrayLikeSequence
.
Signature
ArrayLikeSequence.define = function(methodName, overrides) { /*...*/ }
ArrayLikeSequence.define = function define(methodName, overrides) { if (!overrides || typeof overrides.get !== 'function') { throw new Error("A custom array-like sequence must implement *at least* get!"); } return defineSequenceType(ArrayLikeSequence, methodName, overrides); }
Name | Type(s) | Description |
---|---|---|
methodName | string|Array.<string> | The name(s) of the method(s) to be used for constructing the new sequence. The method will be attached to the |
overrides | Object | An object containing function overrides for this new sequence type. Must include |
returns | Function | A constructor for a new type inheriting from |
Examples
Lazy.ArrayLikeSequence.define("offset", { init: function(offset) { this.offset = offset; }, get: function(i) { return this.parent.get((i + this.offset) % this.parent.length()); } }); Lazy([1, 2, 3]).offset(1) // sequence: [2, 3, 1]