Skip to content

Commit 51f92db

Browse files
committed
polymorphic this
1 parent 591254e commit 51f92db

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

polymorphicThis/polymorphicThis.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
var __extends = (this && this.__extends) || function (d, b) {
2+
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
3+
function __() { this.constructor = d; }
4+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
5+
};
6+
var A = (function () {
7+
function A() {
8+
}
9+
A.prototype.foo = function () {
10+
return this;
11+
};
12+
return A;
13+
})();
14+
var B = (function (_super) {
15+
__extends(B, _super);
16+
function B() {
17+
_super.apply(this, arguments);
18+
}
19+
B.prototype.bar = function () {
20+
return this;
21+
};
22+
return B;
23+
})(A);
24+
var b;
25+
var x = b.foo().bar();

polymorphicThis/polymorphicThis.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class A {
2+
foo() {
3+
return this;
4+
}
5+
}
6+
7+
class B extends A {
8+
bar() {
9+
return this;
10+
}
11+
}
12+
13+
var b: B;
14+
var x = b.foo().bar(); // Fluent pattern works, type of x is B

polymorphicThis/tsconfig.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5",
4+
"module": "commonjs",
5+
"moduleResolution": "node",
6+
"isolatedModules": false,
7+
"jsx": "react",
8+
"experimentalDecorators": true,
9+
"emitDecoratorMetadata": true,
10+
"declaration": false,
11+
"noImplicitAny": false,
12+
"removeComments": true,
13+
"noLib": false,
14+
"preserveConstEnums": true,
15+
"suppressImplicitAnyIndexErrors": true
16+
},
17+
"filesGlob": [
18+
"./**/*.ts",
19+
"./**/*.tsx",
20+
"!./node_modules/**/*"
21+
],
22+
"files": [
23+
"./polymorphicThis.ts"
24+
]
25+
}

0 commit comments

Comments
 (0)