@zwa73/utils 1.0.64 → 1.0.66

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { ComposedClassMult, ComposedClassPart, FuncPropNames, JToken, PromiseProcFn, PromiseVerifyFn } from "./UtilInterfaces";
1
+ import { ComposedClassMult, ComposedClassPart, JToken, PromiseProcFn, PromiseVerifyFn } from "./UtilInterfaces";
2
2
  /**常用函数 */
3
3
  export declare namespace UtilFunc {
4
4
  /**获取当前时间戳
@@ -64,7 +64,7 @@ export declare namespace UtilFunc {
64
64
  * @param fields - 需要混入的字段
65
65
  * @returns 混合完成的类
66
66
  */
67
- function composeClassPart<Base extends object, Mixin extends object, Field extends FuncPropNames<Mixin>>(base: Base, mixin: Mixin, ...fields: Field[]): ComposedClassPart<Base, Mixin, Field>;
67
+ function composeClassPart<Base extends object, Mixin extends object, Field extends keyof Mixin>(base: Base, mixin: Mixin, ...fields: Field[]): ComposedClassPart<Base, Mixin, Field>;
68
68
  /**类组合
69
69
  * 将mixinList每个成员的字段混入base
70
70
  * @param base - 基础类
@@ -216,7 +216,19 @@ var UtilFunc;
216
216
  configurable: true
217
217
  });
218
218
  */
219
- compObj[fd] = mixin[fd].bind(mixin);
219
+ if (typeof mixin[fd] === 'function') {
220
+ compObj[fd] = (...args) => mixin[fd].apply(mixin, args);
221
+ //(compObj as any)[fd] = (mixin[fd] as any).bind(mixin);
222
+ }
223
+ else {
224
+ Object.defineProperty(compObj, fd, {
225
+ get: () => mixin[fd],
226
+ set: (value) => { mixin[fd] = value; },
227
+ enumerable: true,
228
+ //writable: true ,
229
+ configurable: true
230
+ });
231
+ }
220
232
  }
221
233
  return compObj;
222
234
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zwa73/utils",
3
- "version": "1.0.64",
3
+ "version": "1.0.66",
4
4
  "description": "my utils",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -221,7 +221,7 @@ export async function repeatPromise<T>(procFn:PromiseProcFn<T>,verifyFn?:Promise
221
221
  * @returns 混合完成的类
222
222
  */
223
223
  export function composeClassPart
224
- <Base extends object,Mixin extends object,Field extends FuncPropNames<Mixin>>
224
+ <Base extends object,Mixin extends object,Field extends keyof Mixin>
225
225
  (base:Base,mixin:Mixin,...fields:Field[]):ComposedClassPart<Base,Mixin,Field>{
226
226
  const compObj = base as any;
227
227
  for(const fd of fields){
@@ -234,7 +234,18 @@ export function composeClassPart
234
234
  configurable: true
235
235
  });
236
236
  */
237
- (compObj as any)[fd] = (mixin[fd] as any).bind(mixin);
237
+ if(typeof mixin[fd] === 'function') {
238
+ (compObj as any)[fd] = (...args: any[]) => (mixin[fd] as any).apply(mixin, args);
239
+ //(compObj as any)[fd] = (mixin[fd] as any).bind(mixin);
240
+ } else {
241
+ Object.defineProperty(compObj, fd, {
242
+ get: ()=>mixin[fd],
243
+ set: (value)=>{mixin[fd] = value},
244
+ enumerable:true ,
245
+ //writable: true ,
246
+ configurable: true
247
+ });
248
+ }
238
249
  }
239
250
  return compObj;
240
251
  }