UNPKG

plugin-tls

Version:

plugin-tls 是插件系统相应的工具,可快速地让任何模块具备插件机制

81 lines (38 loc) 1.63 kB
<!-- Do not edit this file. It is automatically generated by API Documenter. --> [Home](./index.md) &gt; [plugin-tls](./plugin-tls.md) &gt; [defineExtendWithInit](./plugin-tls.defineextendwithinit.md) ## defineExtendWithInit() function 定义扩展的类型便利函数 **Signature:** ```typescript export declare function defineExtendWithInit<C extends ClassType, E>(cla: C, ext: E & ThisType<InstanceType<C> & E> & PrivateMemberOfExtendWithInit<C>): E & ThisType<C & E>; ``` ## Parameters <table><thead><tr><th> Parameter </th><th> Type </th><th> Description </th></tr></thead> <tbody><tr><td> cla </td><td> C </td><td> 扩展的目标,用作 this 的类型 </td></tr> <tr><td> ext </td><td> E &amp; ThisType&lt;InstanceType&lt;C&gt; &amp; E&gt; &amp; [PrivateMemberOfExtendWithInit](./plugin-tls.privatememberofextendwithinit.md)<!-- -->&lt;C&gt; </td><td> 描述扩展内容的对象,会自动更改其this的类型 </td></tr> </tbody></table> **Returns:** E &amp; ThisType&lt;C &amp; E&gt; 返回注入了 this 类型的 ext 对象本身 ## Remarks 它会更改 ext 中方法的this指向为 cla &amp; ext,不会真的执行扩展操作。 其中: - ext.\_constructor 会被保存在 cla.\_constructors 属性中,它是一个数组。 - ext.\_init 会被保存在 cla.\_inits 属性中,它是一个数组。 cla 需要: - 在自己的构建函数中逐个调用 cla.\_constructors 中的函数 - 在自己的类似初始化`init()` 方法中逐个调用 cla.\_constructors 中的函数