LoeiFy/Mirror

i'm reading your source code, i have a problem invited you

labike opened this issue · 2 comments

i found in source code, many class has get xx(), i'm not undertand What time use get xx(), and what time not use get xx()? the both difference?

example:

class User {
    constructor(selector) {
        this.container = $(selector)
        this.user = null
    }

    get email() {
        const email = this.user.email || this.user.organizationBillingEmail
        return email ? `<a target="_blank" href="mailto:${email}">${emailIcon}</a>` : ''
    }
}

see this: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes#Prototype_methods

this code

class User {
    constructor(selector) {
        this.container = $(selector)
        this.user = null
    }

    get email() {
        const email = this.user.email || this.user.organizationBillingEmail
        return email ? `<a target="_blank" href="mailto:${email}">${emailIcon}</a>` : ''
    }
}

const user = new User()
console.log(user.email) // key value

same as

class User {
    constructor(selector) {
        this.container = $(selector)
        this.user = null
    }

   email() {
        const email = this.user.email || this.user.organizationBillingEmail
        return email ? `<a target="_blank" href="mailto:${email}">${emailIcon}</a>` : ''
    }
}
const user = new User()
console.log(user.email()) // function

thanks! i learning many ES6/7 knowledge and skill from you code!