index.js 372 B

123456789101112131415161718
  1. function User ( name ) {
  2. this.name = name
  3. this.id = this.counter()
  4. }
  5. User.prototype.counter = (function () {
  6. let id = 0
  7. return function(){
  8. return typeof this.id === 'number' ? this.id : id++
  9. }
  10. })()
  11. var users = [
  12. new User ( "Семен" ),
  13. new User ( "Антон" ),
  14. new User ( "Демьян" ),
  15. new User ( "Василий" )
  16. ]