Created
December 14, 2019 19:09
-
-
Save metanomial/e0c56861af0c3cfaf0268c6aa30bdb82 to your computer and use it in GitHub Desktop.
This file contains 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
import { UUIDGen } from './utils/UUID.js'; | |
const uuidGen = UUIDGen(); | |
// Object property definition method | |
class User { | |
constructor() { | |
Object.define(this, 'uuid', { | |
value: uuidGen.next(), | |
writable: false, | |
configurable: false | |
}); | |
} | |
} | |
// Private field | |
class User { | |
#uuid = uuidGen.next(); | |
get uuid() { | |
return this.#uuid; | |
} | |
} | |
// Definition shorthand | |
class User { | |
uuid := { | |
value: uuidGen.next(), | |
writable: false, | |
configurable: false | |
} | |
} |
This file contains 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
const object = { | |
a: 5 | |
}; | |
// Object property definition method | |
Object.defineProperty(object, 'aa', { | |
get: () => object.a * 2, | |
set: (value) => object.a = value / 2, | |
enumerable: false | |
}); | |
// Definition shorthand | |
object.aa := { | |
get: () => object.a * 2, | |
set: (value) => object.a = value / 2, | |
enumerable: false | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment