Merge branch 'master' of https://github.com/Microsoft/pxt-microbit
This commit is contained in:
commit
6f00384891
@ -27,5 +27,10 @@ Visit the cards below to starting programming JavaScript and TypeScript with the
|
|||||||
},{
|
},{
|
||||||
"name": "Classes",
|
"name": "Classes",
|
||||||
"url": "/js/classes"
|
"url": "/js/classes"
|
||||||
}]
|
},{
|
||||||
|
"name": "FAQ",
|
||||||
|
"url": "/js/faq"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
```
|
```
|
||||||
|
58
docs/js/faq.md
Normal file
58
docs/js/faq.md
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
# Frequently asked questions
|
||||||
|
|
||||||
|
# What is the language supported for the micro:bit?
|
||||||
|
|
||||||
|
For the micro:bit, we support a "static" subset of TypeScript (itself a superset of JavaScript):
|
||||||
|
|
||||||
|
## Supported language features
|
||||||
|
|
||||||
|
* variables with `let`, `const`, and `var`
|
||||||
|
* functions with lexical scoping and recursion
|
||||||
|
* top-level code in the file; hello world really is `console.log("Hello world")`
|
||||||
|
* `if ... else if ... else` statements
|
||||||
|
* `while` and `do ... while` loops
|
||||||
|
* `for(;;)` loops (see below about `for ... in/of`)
|
||||||
|
* `break/continue`; also with labeled loops
|
||||||
|
* `switch` statement (on numbers only)
|
||||||
|
* `debugger` statement for breakpoints
|
||||||
|
* conditional operator `? :`; lazy boolean operators
|
||||||
|
* namespaces (a form of modules)
|
||||||
|
* all arithmetic operators (including bitwise operators); note that in microcontroller targets
|
||||||
|
all arithmetic is performed on integers, also when simulating in the browser
|
||||||
|
* strings (with a few common methods)
|
||||||
|
* [string templates](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) (`` `x is ${x}` ``)
|
||||||
|
* arrow functions `() => ...`
|
||||||
|
* classes with fields, methods and constructors; `new` keyword
|
||||||
|
* array literals `[1, 2, 3]`
|
||||||
|
* enums
|
||||||
|
|
||||||
|
## Unsupported language features
|
||||||
|
|
||||||
|
We generally stay away from the more dynamic parts of JavaScript.
|
||||||
|
Things you may miss and we may implement:
|
||||||
|
|
||||||
|
* exceptions (`throw`, `try ... catch`, `try ... finally`)
|
||||||
|
* `for ... of` statements
|
||||||
|
* object literals `{ foo: 1, bar: "two" }`
|
||||||
|
* method-like properties (get/set accessors)
|
||||||
|
* class inheritance
|
||||||
|
|
||||||
|
For JS-only targets we may implement the following:
|
||||||
|
|
||||||
|
* regular expressions
|
||||||
|
* classes implementing interfaces
|
||||||
|
|
||||||
|
Things that we are not very likely to implement:
|
||||||
|
|
||||||
|
* file-based modules (`import * from ...`, `module.exports` etc); we do support namespaces
|
||||||
|
* spread operator
|
||||||
|
* `yield` expression and ``function*``
|
||||||
|
* `await` expression and `async function`
|
||||||
|
* `typeof` expression
|
||||||
|
* tagged templates ``tag `text ${expression} more text` ``; regular templates are supported
|
||||||
|
* binding with arrays or objects: `let [a, b] = ...; let { x, y } = ...`
|
||||||
|
* `with` statement
|
||||||
|
* `eval`
|
||||||
|
* `delete` statement
|
||||||
|
* `for ... in` statements
|
||||||
|
* JSX (HTML as part of JavaScript)
|
@ -35,7 +35,7 @@ basic.showNumber(1);
|
|||||||
basic.showNumber(2);
|
basic.showNumber(2);
|
||||||
```
|
```
|
||||||
|
|
||||||
## The empty statement
|
### The empty statement
|
||||||
|
|
||||||
In JavaScript, there is the concept of an *empty statement*, which is whitespace followed by
|
In JavaScript, there is the concept of an *empty statement*, which is whitespace followed by
|
||||||
a semicolon in the context where a statement is expected.
|
a semicolon in the context where a statement is expected.
|
||||||
|
@ -22,15 +22,3 @@ control.inBackground(() => {
|
|||||||
|
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
## Advanced
|
|
||||||
|
|
||||||
```namespaces
|
|
||||||
devices.tellCameraTo(MesCameraEvent.TakePhoto);
|
|
||||||
bluetooth.onBluetoothConnected(() => {});
|
|
||||||
```
|
|
||||||
|
|
||||||
```package
|
|
||||||
microbit-devices
|
|
||||||
microbit-bluetooth
|
|
||||||
```
|
|
Loading…
Reference in New Issue
Block a user