/**
 *****************************************
 * Created by edonet@163.com
 * Created on 2020-08-22 16:24:52
 *****************************************
 */ 'use strict' ; /**
 *****************************************
 * 生成缓存对象
 *****************************************
 */ export default function cache < T extends object > ( target ) { const cached = Object . create ( null ) ; const proxy = Object . create ( target ) ; Object . keys ( target ) . forEach ( key => { const handler = target [ key as keyof T ] ; if ( typeof handler === 'function' ) { Object . defineProperty ( proxy , key , { value : ( ... args ) => { if ( key in cached ) { return cached [ key ] ; } return cached [ key ] = handler . apply ( proxy , args ) ; } , } ) ; } } ) ; return proxy ; }