Skip to content

Instantly share code, notes, and snippets.

@Aleksey-Danchin
Created October 14, 2016 19:37
Show Gist options
  • Save Aleksey-Danchin/0766c5ef02bf6992f947a5422b62b09d to your computer and use it in GitHub Desktop.
Save Aleksey-Danchin/0766c5ef02bf6992f947a5422b62b09d to your computer and use it in GitHub Desktop.
Синтаксис статического геттера.
class User {
constructor (isAdmin = false) {
const user = this;
user.isAdmin = isAdmin;
User.all.push(user);
}
static get admins () {
return User.all.filter(user => user.isAdmin);
}
}
User.all = [];
for (let i = 0; i < 100; i++)
new User(Math.random() > Math.random());
User.admins.length; // 51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment