Arrow Function 箭头功能

Arrow Function 箭头功能

Trigger 扳机 Description 描述 Result JS/TS 结果 JS/TS
af→ implicit return without arg(s)
不带参数的隐式返回
() => █
afa→ implicit return with arg(s)
带 arg 的隐式返回
(░arg) => █
afad→ implicit return with arg destructuring
带 arg 解构的隐式返回
({░prop, ░prop}) => █
afo→ implicit return object 隐式返回对象 () => ({░prop: value█})
afoa→ implicit return object with arg(s)
带有 arg(s) 的隐式返回对象
(░arg) => ({░prop: value█})
afe→ explicit return 显式返回 () => {
░return █
}
afea→ explicit return with arg(s)
带 arg 的显式返回
(░arg) => {
░return █
}
afead→ explicit return with arg destructuring
带有 arg 解构的显式返回
({░prop, ░prop}) => {
░return █
}
afee→ explicit empty 显式空 () => {

}
afeea→ explicit empty with arg(s)
带有 arg 的显式空
(░arg) => {

}
afp→ explicit with parentheses
带括号显式
() => {
(█)
}
afpa→ explicit with parentheses and arg(s)
带有括号和参数的显式
(░arg) => {
(█)
}
afii→ immediately invoque 立即发票 (() => █)()
iiaf→ immediately invoque 立即发票 (() => █)()

Async Arrow Functions 异步箭头函数

Trigger 扳机 Description 描述 Result JS/TS 结果 JS/TS
aaf→ implicit return without arg(s)
不带参数的隐式返回
async () => █
aafa→ implicit return with arg(s)
带 arg 的隐式返回
async (░arg) => █
aafad→ implicit with arg destructuring
隐含的 arg 解构
async ({ ░prop }) => █
aafe→ explicit return 显式返回 async () => {
░return █
}
aafea→ explicit return with arg(s)
带 arg 的显式返回
async (░arg) => {
░return █
}
aafead→ explicit return with arg destructuring
带有 arg 解构的显式返回
async ({░prop, ░prop}) => {
░return █
}
aafee→ explicit empty 显式空 async () => {

}
aafeea→ explicit empty with arg(s)
带有 arg 的显式空
async (░arg) => {

}
aaafea→ explicit with args and await
显式使用 args 和 wait
async (░arg) => {
const ░name = await █
}
aafii→ immediately invoked 立即调用 (async () => █)()
iiaaf→ immediately invoked 立即调用 (async () => █)()

Promises 承诺

Trigger 扳机 Description 描述 Result JS/TS 结果 JS/TS
afpr→ promise implicit returns
承诺隐性回报
░promise
.then((░response) => {░})
.catch((░error) => {░})
.finally(() => {░})█
}
afr→ implicit return response
隐式返回响应
(░response) => █
afrj→ implicit return response json
隐式返回响应json
(░response) => ░response.json()█
afrd→ implicit return response data
隐式返回响应数据
(░response) => ░response.data█
afer→ explicit return response
显式返回响应
(░response) => {
░return █
}
aferj→ explicit return response json
显式返回响应json
(░response) => {
return ░response.json()
}█
aferd→ explicit return response data
显式返回响应数据
(░response) => {
return ░response.data
}█

Arrays 数组

Trigger 扳机 Description 描述 Result JS/TS 结果 JS/TS
arfeq→ filter equal 过滤等于 const ░newArray = ░array.filter((░element) => ░element === ░value)█
arfne→ filter not equal 过滤器不等于 const ░newArray = ░array.filter((░element) => ░element !== ░value)█
arfoeq→ filter object equal 过滤对象相等 const ░newArray = ░array.filter((░element) => ░element.░prop === ░value)█
arfone→ filter object not equal
过滤对象不相等
const ░newArray = ░array.filter((░element) => ░element.░prop !== ░value)█
arssa→ sort string ascending 字符串升序排序 ░array.░sort((a, z) => a.localeCompare(z))█
arssd→ sort string descending 字符串降序排序 ░array.░sort((a, z) => z.localeCompare(a))█
arsna→ sort number ascending 按升序排列数字 ░array.░sort((a, z) => a - z)█
arsnd→ sort number descending 数字降序排列 ░array.░sort((a, z) => z - a)█
arsba→ sort boolean ascending 布尔值升序排序 ░array.░sort((a, z) => Boolean(a) - Boolean(z))█
arsbd→ sort boolean descending 布尔值降序排序 ░array.░sort((a, z) => Boolean(z) - Boolean(a))█
arsda→ sort date ascending 日期升序排序 ░array.░sort((a, z) => new Date(a) - new Date(z))█
arsdd→ sort date descending 日期降序排序 ░array.░sort((a, z) => new Date(z) - new Date(a))█
arso→ sort object by properties
按属性对对象进行排序
░array.░sort((a, z) => {
const sort = {
░propString: a.░propString.localeCompare(z.░propString),
░propNumber: a.░propNumber - z.░propNumber,
░propBoolean: Boolean(a.░propBoolean) - Boolean(z.░propBoolean),
░propDate: new Date(a.░propDate) - new Date(z.░propDate),
}

return sort.░propString || -sort.░propNumber || sort.░propBoolean || sort.░propDate
})█

arus→ unsort / shuffle 取消排序/随机播放 ░array.░sort(() => Math.random() - 0.5)█
aruv→ unique values 独特的价值观 const ░newArray = ░array.filter((░current, ░index, ░arr) => ░arr.indexOf(░current) == ░index)█

Functions 功能

Trigger 扳机 Description 描述 Result JS 结果JS Result TS 结果 TS
edaf→ export default anonymous arrow function
导出默认匿名箭头函数
export default (░) => {

}
export default (░) => {

}
edaaf→ export default async anonymous arrow function
导出默认异步匿名箭头函数
export default async (░) => {

}
export default async (░) => {

}
caf→ const arrow function implicit return
const 箭头函数隐式返回
const ░name = (░) => █ const ░name = (░) => █
cafe→ const arrow function explicit return
const 箭头函数显式返回
const ░name = (░) => {
░return █
}
const ░name = (░) => {
░return █
}
ecaf→ export const arrow function
导出常量箭头函数
export const ░name = (░) => {

}
export const ░name = (░) => {

}
caaf→ const async arrow function
const 异步箭头函数
const ░name = async (░) => {

}
const ░name = async (░) => {

}
ecaaf→ export const async arrow function
导出 const 异步箭头函数
export const ░name = async (░) => {

}
export const ░name = async (░) => {

}
caft→ const arrow function with type
带类型的 const 箭头函数
const ░name = (░) : ░type => {

}
ecaft→ export const arrow function with type
导出带有类型的常量箭头函数
export const ░name = (░) : ░type => {

}
caaft→ const async arrow function with type
带类型的 const 异步箭头函数
const ░name = async (░) : ░type => {

}
ecaaft→ export const async arrow function with type
导出带有类型的 const 异步箭头函数
export const ░name = async (░) : ░type => {

}

通过 VS Code 创建和使用箭头函数的快速、简单的方法。

https://marketplace.visualstudio.com/items?itemName=deinsoftware.arrow-function-snippets#menu

 

© 版权声明

相关文章

暂无评论

暂无评论...