minor cleanup to JS docs
This commit is contained in:
parent
5098eaac5a
commit
92508d2daf
@ -34,10 +34,6 @@ This calls into the constructor we defined earlier, creating a new object with t
|
||||
|
||||
# Inheritance
|
||||
|
||||
### ~hint
|
||||
### Inheritance is not supported yet for the @boardname@. Coming soon...
|
||||
### ~
|
||||
|
||||
In TypeScript, we can use common object-oriented patterns.
|
||||
Of course, one of the most fundamental patterns in class-based programming is being able to extend existing classes to create new ones using inheritance.
|
||||
|
||||
|
@ -29,8 +29,6 @@ function addToZ(x: number, y: number) {
|
||||
basic.showNumber(addToZ(1, 2))
|
||||
```
|
||||
|
||||
## Typing the function
|
||||
|
||||
Let's add a return type to our add function:
|
||||
|
||||
```typescript
|
||||
@ -41,6 +39,19 @@ function add(x: number, y: number): number {
|
||||
|
||||
TypeScript can figure the return type out by looking at the return statements, so you can optionally leave this off in many cases.
|
||||
|
||||
# Arrow Functions
|
||||
|
||||
Arrow functions (also known as "lamba" functions) are used extensively to provide event handlers for
|
||||
many APIs. For example:
|
||||
|
||||
```typescript
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
|
||||
})
|
||||
```
|
||||
|
||||
[Read more about arrow functions...](http://devdocs.io/javascript/functions/arrow_functions)
|
||||
|
||||
# Optional and Default Parameters
|
||||
|
||||
In TypeScript, the number of arguments given to a function has to match the number of parameters the function expects.
|
||||
|
@ -18,13 +18,6 @@ This also is true when simulating in the browser.
|
||||
* comparison operators - [read more](http://devdocs.io/javascript/operators/comparison_operators)
|
||||
* conditional operator - [read more](http://devdocs.io/javascript/operators/conditional_operator)
|
||||
|
||||
## More
|
||||
|
||||
* lambda functions `() => { ... }`
|
||||
* array literals `[1, 2, 3]`
|
||||
* strings, with a few common methods
|
||||
* [string templates](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) (`` `x is ${x}` ``)
|
||||
|
||||
### ~button /js/statements
|
||||
NEXT: Statements
|
||||
### ~
|
@ -3,6 +3,22 @@
|
||||
For programs to be useful, we need to be able to work with some of the simplest units of data:
|
||||
numbers, strings, structures, boolean values, and the like.
|
||||
|
||||
# Type Inference
|
||||
|
||||
In TypeScript, there are several places where type inference is used to provide type information when there is
|
||||
no explicit type annotation. For example, in this code
|
||||
|
||||
```typescript
|
||||
let x = 3;
|
||||
let y = x + 3
|
||||
```
|
||||
|
||||
The type of the `x` variable is inferred to be `number`. Similarly, the type of `y` variable also is inferred to be `number`.
|
||||
This kind of inference takes place when initializing variables and members,
|
||||
setting parameter default values, and determining function return types.
|
||||
|
||||
All the examples below give an example type annotation, but will work just the same without the annotation.
|
||||
|
||||
# Boolean
|
||||
|
||||
The most basic datatype is the simple true/false value, which is called a `boolean` value.
|
||||
@ -77,7 +93,6 @@ let list: Array<number> = [1, 2, 3];
|
||||
For the @boardname@, all elements of an array must have the same type.
|
||||
### ~
|
||||
|
||||
|
||||
# Enum
|
||||
|
||||
A helpful addition to the standard set of datatypes from JavaScript is the `enum`.
|
||||
@ -108,7 +123,6 @@ let c: Color = Color.Green;
|
||||
|
||||
The TypeScript type `any` is not supported in the @boardname@.
|
||||
|
||||
|
||||
# Void
|
||||
|
||||
`void` is the absence of having any type at all.
|
||||
@ -122,21 +136,6 @@ function warnUser(): void {
|
||||
|
||||
Declaring variables of type `void` is not useful.
|
||||
|
||||
# Type Inference
|
||||
|
||||
In TypeScript, there are several places where type inference is used to provide type information when there is
|
||||
no explicit type annotation. For example, in this code
|
||||
|
||||
```typescript
|
||||
let x = 3;
|
||||
let y = x + 3
|
||||
```
|
||||
|
||||
The type of the `x` variable is inferred to be `number`. Similarly, the type of `y` variable also is inferred to be `number`.
|
||||
This kind of inference takes place when initializing variables and members,
|
||||
setting parameter default values, and determining function return types.
|
||||
|
||||
|
||||
### ~button /js/classes
|
||||
NEXT: Classes
|
||||
### ~
|
@ -1,6 +1,6 @@
|
||||
# Variable Declarations
|
||||
|
||||
Declaring a variable should be done using the ``let`` keyworld:
|
||||
Declaring a variable should be done using the ``let`` keyword:
|
||||
|
||||
```typescript
|
||||
let a = 10;
|
||||
@ -24,6 +24,10 @@ let a = 10;
|
||||
|
||||
The key difference is not in the syntax, but in the semantics, which we'll now dive into.
|
||||
|
||||
### ~hint
|
||||
### Use `let` instead of `var` to introduce a new variable.
|
||||
### ~
|
||||
|
||||
## Block-scoping
|
||||
|
||||
When a variable is declared using `let`, it uses what some call *lexical-scoping* or *block-scoping*.
|
||||
|
Loading…
Reference in New Issue
Block a user