2017-10-07 04:46:29 +02:00
|
|
|
abstract class AbstractClass {
|
2017-10-16 18:43:49 +02:00
|
|
|
constructor(str: string, other: AbstractClass) {
|
2017-10-07 04:46:29 +02:00
|
|
|
this.method(parseInt(str));
|
|
|
|
let val = this.prop.toLowerCase();
|
2017-10-09 19:57:08 +02:00
|
|
|
|
|
|
|
if (!str) {
|
|
|
|
this.prop = "Hello World";
|
|
|
|
}
|
|
|
|
this.cb(str);
|
|
|
|
|
2017-10-16 18:43:49 +02:00
|
|
|
// OK, reference is inside function
|
2017-10-09 19:57:08 +02:00
|
|
|
const innerFunction = () => {
|
|
|
|
return this.prop;
|
|
|
|
}
|
2017-10-16 18:43:49 +02:00
|
|
|
|
|
|
|
// OK, references are to another instance
|
|
|
|
other.cb(other.prop);
|
2017-10-07 04:46:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
abstract prop: string;
|
2017-10-09 19:57:08 +02:00
|
|
|
abstract cb: (s: string) => void;
|
2017-10-07 04:46:29 +02:00
|
|
|
|
|
|
|
abstract method(num: number): void;
|
|
|
|
|
2018-08-14 22:38:03 +02:00
|
|
|
other = this.prop;
|
|
|
|
fn = () => this.prop;
|
|
|
|
|
2017-10-07 04:46:29 +02:00
|
|
|
method2() {
|
|
|
|
this.prop = this.prop + "!";
|
|
|
|
}
|
|
|
|
}
|
2017-10-16 18:20:28 +02:00
|
|
|
|
2018-09-06 08:52:53 +02:00
|
|
|
abstract class DerivedAbstractClass extends AbstractClass {
|
|
|
|
cb = (s: string) => {};
|
|
|
|
|
|
|
|
constructor(str: string, other: AbstractClass, yetAnother: DerivedAbstractClass) {
|
|
|
|
super(str, other);
|
|
|
|
// there is no implementation of 'prop' in any base class
|
|
|
|
this.cb(this.prop.toLowerCase());
|
|
|
|
|
|
|
|
this.method(1);
|
|
|
|
|
|
|
|
// OK, references are to another instance
|
|
|
|
other.cb(other.prop);
|
|
|
|
yetAnother.cb(yetAnother.prop);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Implementation extends DerivedAbstractClass {
|
|
|
|
prop = "";
|
|
|
|
cb = (s: string) => {};
|
|
|
|
|
|
|
|
constructor(str: string, other: AbstractClass, yetAnother: DerivedAbstractClass) {
|
|
|
|
super(str, other, yetAnother);
|
|
|
|
this.cb(this.prop);
|
|
|
|
}
|
|
|
|
|
|
|
|
method(n: number) {
|
|
|
|
this.cb(this.prop + n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-16 18:20:28 +02:00
|
|
|
class User {
|
|
|
|
constructor(a: AbstractClass) {
|
|
|
|
a.prop;
|
|
|
|
a.cb("hi");
|
|
|
|
a.method(12);
|
|
|
|
a.method2();
|
|
|
|
}
|
|
|
|
}
|