当前位置: 首页 > 文档资料 > Lazy.js 英文文档 >

memoize

优质
小牛编辑
137浏览
2023-12-01

Provides an indexed, memoized view into the sequence. This will cache the result whenever the sequence is first iterated, so that subsequent iterations will access the same element objects.

Signature

Sequence.memoize = function() { /*...*/ }
Sequence.memoize = function memoize() {
  return new MemoizedSequence(this);
}
NameType(s)Description
returnsArrayLikeSequence

An indexed, memoized sequence containing this sequence's elements, cached after the first iteration.

Examples

function createObject() { return new Object(); }

var plain    = Lazy.generate(createObject, 10),
memoized = Lazy.generate(createObject, 10).memoize();

plain.toArray()[0] === plain.toArray()[0];       // => false
memoized.toArray()[0] === memoized.toArray()[0]; // => true