chore: add example for return this
This commit is contained in:
parent
c365c15639
commit
e6f341f632
5 changed files with 12 additions and 0 deletions
|
@ -97,6 +97,7 @@ Generated by [AVA](https://avajs.dev).
|
||||||
export class ClassWithFactory {␊
|
export class ClassWithFactory {␊
|
||||||
name: string␊
|
name: string␊
|
||||||
static withName(name: string): ClassWithFactory␊
|
static withName(name: string): ClassWithFactory␊
|
||||||
|
setName(name: string): this␊
|
||||||
}␊
|
}␊
|
||||||
export namespace xxh3 {␊
|
export namespace xxh3 {␊
|
||||||
export const ALIGNMENT: number␊
|
export const ALIGNMENT: number␊
|
||||||
|
|
Binary file not shown.
|
@ -112,6 +112,10 @@ test('class factory', (t) => {
|
||||||
const duck = ClassWithFactory.withName('Default')
|
const duck = ClassWithFactory.withName('Default')
|
||||||
t.is(duck.name, 'Default')
|
t.is(duck.name, 'Default')
|
||||||
|
|
||||||
|
const ret = duck.setName('D')
|
||||||
|
t.is(ret.name, 'D')
|
||||||
|
t.is(ret, duck)
|
||||||
|
|
||||||
duck.name = '周黑鸭'
|
duck.name = '周黑鸭'
|
||||||
t.is(duck.name, '周黑鸭')
|
t.is(duck.name, '周黑鸭')
|
||||||
|
|
||||||
|
|
1
examples/napi/index.d.ts
vendored
1
examples/napi/index.d.ts
vendored
|
@ -87,6 +87,7 @@ export class Context {
|
||||||
export class ClassWithFactory {
|
export class ClassWithFactory {
|
||||||
name: string
|
name: string
|
||||||
static withName(name: string): ClassWithFactory
|
static withName(name: string): ClassWithFactory
|
||||||
|
setName(name: string): this
|
||||||
}
|
}
|
||||||
export namespace xxh3 {
|
export namespace xxh3 {
|
||||||
export const ALIGNMENT: number
|
export const ALIGNMENT: number
|
||||||
|
|
|
@ -9,4 +9,10 @@ impl ClassWithFactory {
|
||||||
pub fn with_name(name: String) -> Self {
|
pub fn with_name(name: String) -> Self {
|
||||||
Self { name }
|
Self { name }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[napi]
|
||||||
|
pub fn set_name(&mut self, name: String) -> &Self {
|
||||||
|
self.name = name;
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue