com-tools
Version:
com-tools 提供了一些通用的工具函数;
102 lines (47 loc) • 1.66 kB
Markdown
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) > [com-tools](./com-tools.md) > [defineListenablePropertyGetter](./com-tools.definelistenablepropertygetter.md)
## defineListenablePropertyGetter() function
defineListenablePropertyGetter(obj, prop, getDefault, asGetter) 定义可监听属性的 getter ; 该方法一般经常用于:一些可监听属性在被定义时,还不能定义 getDefault 选项,只能在稍后某个时刻定义 getDefault 选项,此时便可用此函数来简化重新定义 getter 的操作;
**Signature:**
```typescript
export function defineListenablePropertyGetter<T extends object>(obj:T, prop:string, getDefault?:(this:T,thisValue:T)=>any, asGetter?:boolean):void;
```
## Parameters
<table><thead><tr><th>
Parameter
</th><th>
Type
</th><th>
Description
</th></tr></thead>
<tbody><tr><td>
obj
</td><td>
T
</td><td>
: Object 必选;要在其上定义属性的对象。
</td></tr>
<tr><td>
prop
</td><td>
string
</td><td>
: string 必选;要定义的属性的名称。
</td></tr>
<tr><td>
getDefault
</td><td>
(this:T,thisValue:T)=>any
</td><td>
_(Optional)_ ?:(thisValue)=<!-- -->><!-- -->PropValue 可选;在获取 prop 属性的值时,如果 prop 属性的值不存在 ,则会通过 该函数获取默认的值;
</td></tr>
<tr><td>
asGetter
</td><td>
boolean
</td><td>
_(Optional)_ ?: boolean 可选;是否将 getDefault 作为 getter
</td></tr>
</tbody></table>
**Returns:**
void