Created
October 14, 2016 19:37
-
-
Save Aleksey-Danchin/0766c5ef02bf6992f947a5422b62b09d to your computer and use it in GitHub Desktop.
Синтаксис статического геттера.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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