一款AI工具,主要用于使用 Codex CLI 进行深度网络搜索,适用于需要多源综合分析的复杂查询。当 `web_search`(Brave)返回结果不足,或用户……时使用,适合需要提升相关任务效率的用户。
javascript中可用解构赋值+默认参数实现参数合并,右侧设默认值可保留falsy值;嵌套对象需深合并(如用lodash merge或自定义deepmerge);区分undefined与null需手动判断;可封装withdefaults工厂函数复用逻辑。

直接用 JavaScript 的对象展开运算符(...)配合默认参数即可实现参数默认值合并,关键在于默认值对象要放在函数参数解构的右侧,且合并逻辑由开发者控制。
用解构赋值 + 默认参数合并
函数定义时对参数对象进行解构,并为每个字段设置默认值。若传入对象中某字段为 undefined,则使用默认值;若为 null、0、false 或空字符串等“falsy 但非 undefined”值,则保留原值(这是常见需求)。
- 写法示例:
function request({ url = '/api', method = 'GET', timeout = 5000, headers = {} } = {}) {
return { url, method, timeout, headers };
}
调用时传入部分字段,其余自动补默认值:request({ url: '/login', method: 'POST' }) → { url: '/login', method: 'POST', timeout: 5000, headers: {} }
深度合并默认配置(支持嵌套对象)
若默认值和传入参数都含嵌套对象(如 headers),需手动深合并,不能只靠解构默认值。
- 推荐使用轻量工具函数(如 Lodash 的
merge),或自己实现简易版本:
function deepMerge(target, source) {
const result = { ...target };
for (const key in source) {
if (source.hasOwnProperty(key)) {
if (typeof source[key] === 'object' && source[key] !== null && !Array.isArray(source[key]) && typeof result[key] === 'object' && result[key] !== null) {
result[key] = deepMerge(result[key], source[key]);
} else {
result[key] = source[key];
}
}
}
return result;
}
function request(options = {}) {
const defaults = { url: '/api', method: 'GET', timeout: 5000, headers: { 'Content-Type': 'application/json' } };
return deepMerge(defaults, options);
}
区分“未传”和“显式传 null/undefined”
有时需要把 undefined 视为“不覆盖”,而 null 表示“清空该字段”。此时不能依赖解构默认值,需额外判断。
- 做法:先取传入值,再按需 fallback
- 示例:
function request(options = {}) {
const config = {};
config.url = options.url !== undefined ? options.url : '/api';
config.method = options.method !== undefined ? options.method : 'GET';
config.timeout = options.timeout ?? 5000; // ?? 更适合处理 null/undefined
config.headers = options.headers != null ? options.headers : { 'Content-Type': 'application/json' };
return config;
}
封装成可复用的工厂函数
如果多个函数都需要类似能力,可抽象出一个默认合并高阶函数:
const withDefaults = (defaults) => (options = {}) => ({
...defaults,
...options,
headers: { ...defaults.headers, ...(options.headers || {}) }
});
const request = withDefaults({
url: '/api',
method: 'GET',
timeout: 5000,
headers: { 'Content-Type': 'application/json' }
});
这样既保持简洁,又支持浅层合并;如需深层合并,可在工厂内部调用 deepMerge。










