forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/// <reference path="autobind-decorator.d.ts" /> | ||
|
||
import autobind = require('autobind-decorator'); | ||
|
||
class Test { | ||
public static what: string = 'static'; | ||
|
||
@bind | ||
public static test(): void { | ||
console.log(this.what); | ||
} | ||
|
||
public constructor(public what: string) { | ||
this.what = what; | ||
} | ||
|
||
@bind | ||
public test(): void { | ||
console.warn(this.what); | ||
} | ||
} | ||
|
||
const tester: Test = new Test('bind'); | ||
const { test } = tester; | ||
tester.test(); // warns 'bind'. | ||
test(); // warns 'bind'. | ||
Test.test(); // logs 'static'. | ||
|
||
@autobind | ||
class Component { | ||
public constructor(private someMember: string) { | ||
this.someMember = someMember; | ||
} | ||
|
||
public somMethod(): void { | ||
console.error(this.someMember); | ||
} | ||
} | ||
|
||
const component: Component = new Component('React vs Angular2'); | ||
const { somMethod } = component; | ||
component.someMethod(); // errors 'React vs Angular2' | ||
somMethod(); // errors 'React vs Angular2' |