Permalink
Browse files

this 在 class 內使用 arrow function 第二種方法

  • Loading branch information...
1 parent 465c28b commit 2f2a824f497fc1daa0fecd8b382ee4750935bac1 Sam.IO.Hsiao committed Nov 5, 2016
Showing with 34 additions and 0 deletions.
  1. +17 −0 this_class_arrow_function2.js
  2. +1 −0 this_class_arrow_function2.js.map
  3. +16 −0 this_class_arrow_function2.ts
@@ -0,0 +1,17 @@
+var MyModule;
+(function (MyModule) {
+ var Foo = (function () {
+ function Foo(name) {
+ var _this = this;
+ this.name = name;
+ this.say = function () {
+ console.log("Hello, " + _this.name);
+ };
+ }
+ return Foo;
+ }());
+ MyModule.Foo = Foo;
+})(MyModule || (MyModule = {}));
+var foo = new MyModule.Foo('Sam');
+setTimeout(foo.say, 1000);
+//# sourceMappingURL=this_class_arrow_function2.js.map
@@ -0,0 +1 @@
+{"version":3,"file":"this_class_arrow_function2.js","sourceRoot":"","sources":["this_class_arrow_function2.ts"],"names":[],"mappings":"AAAA,IAAO,QAAQ,CAYd;AAZD,WAAO,QAAQ,EAAC,CAAC;IACb;QAII,aAAY,IAAY;YAJ5B,iBAUC;YALO,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;YACjB,IAAI,CAAC,GAAG,GAAG;gBACP,OAAO,CAAC,GAAG,CAAC,YAAU,KAAI,CAAC,IAAM,CAAC,CAAC;YACvC,CAAC,CAAC;QACN,CAAC;QACL,UAAC;IAAD,CAAC,AAVD,IAUC;IAVY,YAAG,MAUf,CAAA;AACL,CAAC,EAZM,QAAQ,KAAR,QAAQ,QAYd;AAED,IAAI,GAAG,GAAG,IAAI,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AAClC,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC"}
@@ -0,0 +1,16 @@
+module MyModule {
+ export class Foo {
+ private name: string;
+ public say: ()=>void;
+
+ constructor(name: string) {
+ this.name = name;
+ this.say = () => {
+ console.log(`Hello, ${this.name}`);
+ };
+ }
+ }
+}
+
+var foo = new MyModule.Foo('Sam');
+setTimeout(foo.say, 1000);

0 comments on commit 2f2a824

Please sign in to comment.