-
-
Save nrigaudiere/85602edc812c77d24c8fda21caae92e6 to your computer and use it in GitHub Desktop.
Revisions
-
jrm2k6 revised this gist
Jun 25, 2014 . 1 changed file with 8 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -76,7 +76,8 @@ Leave spaces inside the braces and after the colons in object literals. If it do // GOOD var point = { x: 100, y: 200 }; var p2 = { x: 100, y: 200 }; @@ -106,9 +107,11 @@ function foo() {} You can declare a class variable directly from the constructor, take advantage of it. It avoids code repetition. ````typescript class Animal { constructor(private name: string) { } move(meters: number) { alert(this.name + " moved " + meters + "m."); } } @@ -118,7 +121,8 @@ class Animal { When you want to bind ```this``` to your callback, you can use the [arrow function](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/arrow_functions) ````javascript```` function Person() { this.age = 0; setInterval(() => { -
jrm2k6 revised this gist
Jun 12, 2014 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -54,6 +54,7 @@ function foo(bar:number):String { ... } * always add types to method signatures * except for the void return type in classes (void return type is required in interfaces) * add types to class variables; it is required * try not to use the ```any``` type. You can always add a definition file from the excellent [Definitely Typed github repo]("https://github.com/borisyankov/DefinitelyTyped") if you want to have more specific type when using a third party library. ``` // GOOD -
jrm2k6 revised this gist
Jun 12, 2014 . 1 changed file with 15 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -112,3 +112,18 @@ class Animal { } } ```` ### arrow function When you want to bind ```this``` to your callback, you can use the [arrow function](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/arrow_functions) ````javascript```` function Person(){ this.age = 0; setInterval(() => { this.age++; // |this| properly refers to the person object }, 1000); } var p = new Person(); ```` -
jrm2k6 revised this gist
Jun 12, 2014 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -55,8 +55,6 @@ function foo(bar:number):String { ... } * except for the void return type in classes (void return type is required in interfaces) * add types to class variables; it is required ``` // GOOD public function setToRotation(radians:number) -
jrm2k6 revised this gist
Jun 12, 2014 . 1 changed file with 24 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -48,23 +48,23 @@ Don’t put spaces around the type defining colon. ``` var _message:String; function foo(bar:number):String { ... } ``` * always add types to method signatures * except for the void return type in classes (void return type is required in interfaces) * add types to class variables; it is required Even if the haxe compiler supports [type inference](http://haxe.org/ref/type_infer) we choose to add types to methods to improve code documentation. ``` // GOOD public function setToRotation(radians:number) { var cos = Math.cos(radians); var sin = Math.sin(radians); ... } ``` Method arguments should be typed. @@ -93,5 +93,24 @@ An empty function should be written in one line. function foo() {} ``` ### variables * No need to prefix variables declaration with public keyword, it is the default visibility in Typescript. * All variables name must be written using the camelCase notation. ### private variables * Prefix all private variables with an underscore ### static variables * Must be written in capitals, separated by underscores if containing several words. ### class constructor You can declare a class variable directly from the constructor, take advantage of it. It avoids code repetition. ````typescript class Animal { constructor(private name: string) { } move(meters: number) { alert(this.name + " moved " + meters + "m."); } } ```` -
jrm2k6 revised this gist
Jun 12, 2014 . 1 changed file with 4 additions and 20 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -48,16 +48,15 @@ Don’t put spaces around the type defining colon. ``` var _message:String; function foo(bar:number):string { ... } ``` * always add types to method signatures * except for the void return type in classes (void return type is required in interfaces) * try to avoid the type ```any``` as much as possible. * you can download definitions files to include in your project from the [Definitely Typed github repo](https://github.com/borisyankov/DefinitelyTyped) ```typescript``` // GOOD public function setToRotation(radians:number) { @@ -66,21 +65,6 @@ public function setToRotation(radians:number) ... } ``` Method arguments should be typed. -
jrm2k6 created this gist
Jun 12, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,113 @@ ## Formatting ### spaces vs. tabs Use only tabs for indentation. Do not use spaces. Yes, spaces would be better :), it's for historical reasons. ### curly braces, control flow * Always put opening curly braces on new line. * Add a space after control flow keywords. * Use braces for single line ifs as well ``` // BAD if(foo){ // do something } // GOOD if (foo) { // do something } // BAD if (foo) bar; // GOOD if (foo) { bar; } ``` ### operators Put spaces around the operator except unary operators. ``` var i = 0; i++; i = i + 1; var s = "hello" + ", " + "world"; ``` ### typing Don’t put spaces around the type defining colon. ``` var _message:String; function foo(bar:number):String { ... } ``` * always add types to method signatures * except for the void return type in classes (void return type is required in interfaces) * add types to class variables; it is required Even if the haxe compiler supports [type inference](http://haxe.org/ref/type_infer) we choose to add types to methods to improve code documentation. ``` // GOOD public function setToRotation(radians:number) { var cos = Math.cos(radians); var sin = Math.sin(radians); ... } // BAD inline public function setToRotation(radians:Float):Void { ... } ``` Void return type shouldn’t be typed. ``` // BAD inline public function setToRotation(radians) { ... } ``` Method arguments should be typed. ### object literals Leave spaces inside the braces and after the colons in object literals. If it doesn't fit easily on one line, break it into one line per field. ```typescript // GOOD var point = { x: 100, y: 200 }; var p2 = { x: 100, y: 200 }; // BAD var point = {x:100,y:200}; ``` ### Empty function An empty function should be written in one line. ``` function foo() {} ``` ### private variables * Prefix all private variables with an underscore