1 Star 0 Fork 0

creatliukun/ts-study

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
16-让this指向自定义的对象.ts 318 Bytes
一键复制 编辑 原始数据 按行查看 历史
creatliukun 提交于 2023-03-27 23:42 . docs: 第二天完善
export {}
type ObjType = { myName: string; Person: (m: string) => void }
let obj: ObjType = { myName: 'zz', Person: () => {} }
// 定义函数的时候,this的烈性,必须和调用的时候类型一致
function Person(this: ObjType, name: string) {
this.myName = name
}
obj.Person = Person
obj.Person('lisa')
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
TypeScript
1
https://gitee.com/creatliukun/ts-study.git
git@gitee.com:creatliukun/ts-study.git
creatliukun
ts-study
ts-study
master

搜索帮助