function counter(n) { return { get count() { let nPlus = n++; console.log('print get count():', nPlus); return nPlus; }, set count(m) { if (m > n) n = m; else throw Error('count can only be set to a larger value'); } } } let c = counter(1000); c.count; c.count; c.count=2000; c.count; c.count=2000;