function fn() { const data = {} return { set: (key, val) => { data[key] = val }, get: (key) => data[key] } } const data = fn() data.set('name', '小明') data.set('age', 18) console.log(data) console.log(data.get('name')) console.log(data.get('age'))