You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
623 B
29 lines
623 B
6 years ago
|
export function prop (object: Object, name: string, f: ()=>any): void {
|
||
7 years ago
|
Object.defineProperty(object, name, {
|
||
|
configurable: true,
|
||
|
enumerable: true,
|
||
|
get: function () {
|
||
|
let value = f.call(this)
|
||
|
this[name] = value
|
||
|
return value
|
||
|
},
|
||
|
set: function (value) {
|
||
|
Object.defineProperty(this, name, {
|
||
|
configurable: true,
|
||
|
enumerable: true,
|
||
|
value: value,
|
||
|
writable: true
|
||
|
})
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
|
||
6 years ago
|
export function value <T> (f: ()=>T): ()=>T {
|
||
6 years ago
|
let value: T
|
||
6 years ago
|
return function (): T {
|
||
7 years ago
|
if (value !== undefined) return value
|
||
|
value = f()
|
||
|
return value
|
||
|
}
|
||
|
}
|