Merge pull request #199 from Microsoft/ignore-snippets

-ignore snippet notation
This commit is contained in:
Peli de Halleux 2016-08-10 08:29:05 -07:00 committed by GitHub
commit a6b4c9645a
11 changed files with 42 additions and 20 deletions

View File

@ -43,7 +43,7 @@ Of course, one of the most fundamental patterns in class-based programming is be
Let's take a look at an example:
```ts
```ts-ignore
class Animal {
name: string;
constructor(theName: string) { this.name = theName; }
@ -105,7 +105,7 @@ In TypeScript, each member is `public` by default.
You may still mark a member `public` explicitly.
We could have written the `Animal` class from the previous section in the following way:
```ts
```ts-ignore
class Animal {
public name: string;
public constructor(theName: string) { this.name = theName; }
@ -119,7 +119,7 @@ class Animal {
When a member is marked `private`, it cannot be accessed from outside of its containing class. For example:
```ts
```ts-ignore
class Animal {
private name: string;
constructor(theName: string) { this.name = theName; }
@ -138,7 +138,7 @@ The same applies to `protected` members.
Let's look at an example to better see how this plays out in practice:
```ts
```ts-ignore
class Animal {
private name: string;
constructor(theName: string) { this.name = theName; }
@ -174,7 +174,7 @@ Even though `Employee` also has a `private` member called `name`, it's not the o
The `protected` modifier acts much like the `private` modifier with the exception that members
declared `protected` can also be accessed by instances of deriving classes. For example,
```ts
```ts-ignore
class Person {
protected name: string;
constructor(name: string) { this.name = name; }
@ -204,7 +204,7 @@ we can still use it from within an instance method of `Employee` because `Employ
A constructor may also be marked `protected`.
This means that the class cannot be instantiated outside of its containing class, but can be extended. For example,
```ts
```ts-ignore
class Person {
protected name: string;
protected constructor(theName: string) { this.name = theName; }
@ -233,7 +233,7 @@ let john = new Person("John"); // Error: The 'Person' constructor is protected
You can make properties readonly by using the `readonly` keyword.
Readonly properties must be initialized at their declaration or in the constructor.
```ts
```ts-ignore
class Octopus {
readonly name: string;
readonly numberOfLegs: number = 8;
@ -252,7 +252,7 @@ This turns out to be a very common practice.
*Parameter properties* let you create and initialize a member in one place.
Here's a further revision of the previous `Octopus` class using a parameter property:
```ts
```ts-ignore
class Octopus {
readonly numberOfLegs: number = 8;
constructor(readonly name: string) {

View File

@ -45,7 +45,7 @@ TypeScript can figure the return type out by looking at the return statements, s
In TypeScript, the number of arguments given to a function has to match the number of parameters the function expects.
```ts
```ts-ignore
function buildName(firstName: string, lastName: string) {
return firstName + " " + lastName;
}
@ -60,7 +60,7 @@ When they do, their value is `undefined`.
We can get this functionality in TypeScript by adding a `?` to the end of parameters we want to be optional.
For example, let's say we want the last name parameter from above to be optional:
```ts
```ts-ignore
function buildName(firstName: string, lastName?: string) {
if (lastName)
return firstName + " " + lastName;
@ -80,7 +80,7 @@ In TypeScript, we can also set a value that a parameter will be assigned if the
These are called default-initialized parameters.
Let's take the previous example and default the last name to `"Smith"`.
```ts
```ts-ignore
function buildName(firstName: string, lastName = "Smith") {
return firstName + " " + lastName;
}
@ -115,7 +115,7 @@ Unlike plain optional parameters, default-initialized parameters don't *need* to
If a default-initialized parameter comes before a required parameter, users need to explicitly pass `undefined` to get the default initialized value.
For example, we could write our last example with only a default initializer on `firstName`:
```ts
```ts-ignore
function buildName(firstName = "Will", lastName: string) {
return firstName + " " + lastName;
}
@ -134,7 +134,7 @@ In JavaScript, you can work with the arguments directly using the `arguments` va
In TypeScript, you can gather these arguments together into a variable:
```ts
```ts-ignore
function buildName(firstName: string, ...restOfName: string[]) {
return firstName + " " + restOfName.join(" ");
}
@ -148,7 +148,7 @@ The compiler will build an array of the arguments passed in with the name given
The ellipsis is also used in the type of the function with rest parameters:
```ts
```ts-ignore
function buildName(firstName: string, ...restOfName: string[]) {
return firstName + " " + restOfName.join(" ");
}

View File

@ -44,7 +44,7 @@ Another property of block-scoped variables is that they can't be read or written
While these variables are "present" throughout their scope, all points up until their declaration are part of their *temporal dead zone*.
This is just a sophisticated way of saying you can't access them before the `let` statement, and luckily TypeScript will let you know that.
```typescript
```typescript-ignore
a++; // illegal to use 'a' before it's declared;
let a;
```

View File

@ -86,3 +86,7 @@ Have fun reviewing your simulation and analyze the acceleration by chart the Exc
* The first person and second person take turns tilting the micro:bit in the "x" direction while the other player charts the data on the micro:bit!
* Review and analyze the actual micro:bit device acceleration data on Excel
* Display acceleration with y or z using plot bar graph by changing acceleration from "x" to "y" or "z"
```package
microbit-radio
```

View File

@ -42,3 +42,7 @@ radio.onDataReceived(() => { })
* learn how to conditionally run code depending on whether a condition is true or not
* learn how to run code when an input button is pressed
* learn how to pause your code for the specified number of milliseconds
```package
microbit-radio
```

View File

@ -162,3 +162,7 @@ radio.onDataReceived(() => {
Connect the first micro:bit to your computer using your USB cable and run the pogo script on it.
Connect the second micro:bit to your computer using your USB cable and run the pogo script on it.
The first person and second person take turns jumping in the “y” direction while the other player uses the micro:bit to track the results on the micro:bit!
```package
microbit-radio
```

View File

@ -33,3 +33,7 @@ radio.receiveNumber();
* learn how to return the sum of the two numbers
* learn how to get acceleration value in milli-gravitys
* learn how to read the connector value as analog as a value comprised between 0 and 1023
```package
microbit-radio
```

View File

@ -195,4 +195,6 @@ Let's select Style 10 as an example.
* The first person and second person take shaking or moving the micor:bit in any direction while the other player charts the data on the micro:bit!
* Review and analyze the actual micro:bit device acceleration data on Excel
```package
microbit-radio
```

View File

@ -89,4 +89,8 @@ Have fun reviewing your simulation and analyze the acceleration by chart the Exc
### ~button /projects/the-watch
NEXT: The Watch
### ~
### ~
```package
microbit-radio
```

View File

@ -41,7 +41,7 @@ let img = images.createImage(`
### ~
```blocks
```typescript-ignore
let state = img.pixel(0, 0)
```

View File

@ -32,7 +32,7 @@ let img = images.createImage(`
### ~
```blocks
```typescript-ignore
let w = img.width()
```
@ -40,7 +40,7 @@ let w = img.width()
The following example uses the `width` function with a [for](/blocks/loops/for) loop to show each image frame on the screen:
```blocks
```typescript
let img2 = images.createImage(`
. . # . . . # # # # . # # # .
. # # . . . . . . # . . . # .