我有以下const str = 'Hello there XXXX, how are you?';
let indexes = Array.from(str, (c, i) => c === 'X' ? i : -1).filter(i => i !== -1);
console.log(indexes);
,还有这样的缓存class
:
property
如何做到这一点,以便每当我使用相同的class Object:
def __init__(self, var):
self._var = var
@property
@lru_cache()
def some_property(self):
print("i did some calculation")
return self._var + 3
>> obj = Object(3)
>> obj.some_property
i did some calculation
6
创建新的Object
时,它都不会重新计算,而是var
的结果胖memoize
而不重新计算class level
。
换句话说,我需要它表现得如此:
somme_property
答案 0 :(得分:0)