strict
优质
小牛编辑
139浏览
2023-12-01
Provides a stricter version of Lazy which throws an error when attempting to wrap null
, undefined
, or numeric or boolean values as a sequence.
Signature
Lazy.strict = function() { /*...*/ }
Lazy.strict = function strict() { function StrictLazy(source) { if (source == null) { throw new Error("You cannot wrap null or undefined using Lazy."); } if (typeof source === "number" || typeof source === "boolean") { throw new Error("You cannot wrap primitive values using Lazy."); } return Lazy(source); }; Lazy(Lazy).each(function(property, name) { StrictLazy[name] = property; }); return StrictLazy; }
Name | Type(s) | Description |
---|---|---|
returns | Function | A stricter version of the Lazy helper function. |
Examples
var Strict = Lazy.strict(); Strict() // throws Strict(null) // throws Strict(true) // throws Strict(5) // throws Strict([1, 2, 3]) // instanceof Lazy.ArrayLikeSequence Strict({ foo: "bar" }) // instanceof Lazy.ObjectLikeSequence Strict("hello, world!") // instanceof Lazy.StringLikeSequence // Let's also ensure the static functions are still there. Strict.range(3) // sequence: [0, 1, 2] Strict.generate(Date.now) // instanceof Lazy.GeneratedSequence