diff --git a/lib/core/src/ajax/fetcher.ts b/lib/core/src/ajax/fetcher.ts index 0ace12b96f..00457fff54 100644 --- a/lib/core/src/ajax/fetcher.ts +++ b/lib/core/src/ajax/fetcher.ts @@ -3,14 +3,14 @@ import {$} from '../cash'; import {Ajax} from './ajax'; import type {AjaxSetting, FetcherSetting} from './types'; -export async function fetchData(setting: FetcherSetting, args: A = ([] as unknown as A), extraAjaxSetting?: Partial | ((ajaxSetting: AjaxSetting) => Partial)): Promise { +export async function fetchData(setting: FetcherSetting, args: A = ([] as unknown as A), extraAjaxSetting?: Partial | ((ajaxSetting: AjaxSetting) => Partial), thisObj?: THIS): Promise { const ajaxSetting = {throws: true, dataType: 'json'} as AjaxSetting; if (typeof setting === 'string') { ajaxSetting.url = formatString(setting, ...args); } else if (typeof setting === 'object') { $.extend(ajaxSetting, setting); } else if (typeof setting === 'function') { - const result = setting(...args); + const result = setting.call(thisObj as THIS, ...args); if (result instanceof Promise) { const data = await result; return data; diff --git a/lib/core/src/ajax/types.ts b/lib/core/src/ajax/types.ts index c385e12f2b..eeb8abace9 100644 --- a/lib/core/src/ajax/types.ts +++ b/lib/core/src/ajax/types.ts @@ -43,6 +43,6 @@ export type FetcherUrl = string; export type FetcherInit = AjaxSetting; -export type FetcherFn = (...args: A) => Promise | T; +export type FetcherFn = (this: THIS, ...args: A) => Promise | T; -export type FetcherSetting = FetcherUrl | FetcherInit | FetcherFn; +export type FetcherSetting = FetcherUrl | FetcherInit | FetcherFn;