Skip to content

Commit

Permalink
Fix JS output in 'Working with JavaScript objects and values' page (#212
Browse files Browse the repository at this point in the history
)
  • Loading branch information
feihong authored Jan 13, 2025
1 parent bfcb841 commit 8fa20f3
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 130 deletions.
10 changes: 5 additions & 5 deletions docs/advanced-js-interop.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ let cancel: action = Cancel;

Which will result in the following JavaScript code after compilation:

```javascript
```js
function submit(param_0) {
return /* Submit */{
_0: param_0
Expand All @@ -85,7 +85,7 @@ Note the generated definitions are lower-cased, and they can be safely used from
JavaScript code. For example, if the above JavaScript generated code was located
in a `generators.js` file, the definitions can be used like this:

```javascript
```js
const generators = require('./generators.js');

const hello = generators.submit("Hello");
Expand Down Expand Up @@ -471,7 +471,7 @@ let bob = nameGet(bob);

This generates:

```javascript
```js
var twenty = alice.age;

var bob = bob.name;
Expand Down Expand Up @@ -507,7 +507,7 @@ let aliceName = name(alice);

Which generates:

```javascript
```js
var alice = {
name: "Alice",
age: 20
Expand Down Expand Up @@ -566,7 +566,7 @@ let () = ageSet(alice, 21);

This will generate:

```javascript
```js
var alice = {
name: "Alice",
age: 20
Expand Down
2 changes: 1 addition & 1 deletion docs/attributes-and-extension-nodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ let f = (x, y) => {

Output:

```javascript
```js
function f (x,y) {
debugger; // JavaScript developer tools will set a breakpoint and stop here
return x + y | 0;
Expand Down
2 changes: 1 addition & 1 deletion docs/bindings-cookbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ let {id, name} = person;
In Melange it is idiomatic to bind to class properties and methods as functions
which take the instance as just a normal function argument. So e.g., instead of

```javascript
```js
const foo = new Foo();
foo.bar();
```
Expand Down
2 changes: 1 addition & 1 deletion docs/data-types-and-runtime-rep.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ let () = React.useEffect2(() => None, (foo, bar));

Will produce:

```javascript
```js
React.useEffect(function () {}, [foo, bar]);
```

Expand Down
8 changes: 4 additions & 4 deletions docs/melange-for-x-developers.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ These are some of the differences between both.

In TypeScript, the types for the input parameters have to be defined:

```javascript
```typescript
let sum = (a: number, b: number) => a + b;
```

Expand Down Expand Up @@ -290,7 +290,7 @@ In TypeScript, all typing is structural. This means that it is hard sometimes to
establish a boundary or separation between two types that have the same
implementation. For these cases, nominal typing can be emulated using tags:

```js
```typescript
type Email = string & { readonly __tag: unique symbol };
type City = string & { readonly __tag: unique symbol };
```
Expand All @@ -313,14 +313,14 @@ TypeScript has two base primitives to work with immutability: `const` and

The first one is used to prevent variable reference change.

```js
```typescript
const a = 1;
a = 2; // Error: Cannot assign to 'a' because it is a constant.
```

And the second one is used to make properties immutable.

```js
```typescript
type A = {
readonly x: number;
}
Expand Down
Loading

0 comments on commit 8fa20f3

Please sign in to comment.