define
优质
小牛编辑
140浏览
2023-12-01
Create a new constructor function for a type inheriting from StringLikeSequence
.
Signature
StringLikeSequence.define = function(methodName, overrides) { /*...*/ }
StringLikeSequence.define = function define(methodName, overrides) { if (!overrides || typeof overrides.get !== 'function') { throw new Error("A custom string-like sequence must implement *at least* get!"); } return defineSequenceType(StringLikeSequence, 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. Has the same requirements as ArrayLikeSequence.define. |
returns | Function | A constructor for a new type inheriting from |
Examples
Lazy.StringLikeSequence.define("zomg", { length: function() { return this.parent.length() + "!!ZOMG!!!1".length; }, get: function(i) { if (i < this.parent.length()) { return this.parent.get(i); } return "!!ZOMG!!!1".charAt(i - this.parent.length()); } }); Lazy('foo').zomg() // sequence: "foo!!ZOMG!!!1"