diff options
| author | Li Jin <dragon-fly@qq.com> | 2022-08-16 15:46:32 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2022-08-16 15:46:32 +0800 |
| commit | a4d4893c77f9c48dedc88472a2e418bfd65e33a1 (patch) | |
| tree | b40dc41ef56c483797e14d269ee164d1c719757e | |
| parent | 5375fd872490eaef7499e344585476edf58005d8 (diff) | |
| download | yuescript-a4d4893c77f9c48dedc88472a2e418bfd65e33a1.tar.gz yuescript-a4d4893c77f9c48dedc88472a2e418bfd65e33a1.tar.bz2 yuescript-a4d4893c77f9c48dedc88472a2e418bfd65e33a1.zip | |
update docs.
Diffstat (limited to '')
| -rwxr-xr-x | doc/docs/doc/README.md | 128 | ||||
| -rwxr-xr-x | doc/package.json | 2 |
2 files changed, 63 insertions, 67 deletions
diff --git a/doc/docs/doc/README.md b/doc/docs/doc/README.md index c6b493c..5f00860 100755 --- a/doc/docs/doc/README.md +++ b/doc/docs/doc/README.md | |||
| @@ -571,68 +571,6 @@ readFile "example.txt" | |||
| 571 | </pre> | 571 | </pre> |
| 572 | </YueDisplay> | 572 | </YueDisplay> |
| 573 | 573 | ||
| 574 | ### Backcall | ||
| 575 | |||
| 576 | Backcalls are used for unnesting callbacks. They are defined using arrows pointed to the left as the last parameter by default filling in a function call. All the syntax is mostly the same as regular arrow functions except that it is just pointing the other way and the function body does not require indent. | ||
| 577 | |||
| 578 | ```moonscript | ||
| 579 | <- f | ||
| 580 | print "hello" | ||
| 581 | ``` | ||
| 582 | <YueDisplay> | ||
| 583 | <pre> | ||
| 584 | <- f | ||
| 585 | print "hello" | ||
| 586 | </pre> | ||
| 587 | </YueDisplay> | ||
| 588 | |||
| 589 | Fat arrow functions are also available. | ||
| 590 | |||
| 591 | ```moonscript | ||
| 592 | <= f | ||
| 593 | print @value | ||
| 594 | ``` | ||
| 595 | <YueDisplay> | ||
| 596 | <pre> | ||
| 597 | <= f | ||
| 598 | print @value | ||
| 599 | </pre> | ||
| 600 | </YueDisplay> | ||
| 601 | |||
| 602 | You can specify a placeholder for where you want the backcall function to go as a parameter. | ||
| 603 | |||
| 604 | ```moonscript | ||
| 605 | (x) <- map _, {1, 2, 3} | ||
| 606 | x * 2 | ||
| 607 | ``` | ||
| 608 | <YueDisplay> | ||
| 609 | <pre> | ||
| 610 | (x) <- map _, {1, 2, 3} | ||
| 611 | x * 2 | ||
| 612 | </pre> | ||
| 613 | </YueDisplay> | ||
| 614 | |||
| 615 | If you wish to have further code after your backcalls, you can set them aside with a do statement. | ||
| 616 | |||
| 617 | ```moonscript | ||
| 618 | result, msg = do | ||
| 619 | (data) <- readAsync "filename.txt" | ||
| 620 | print data | ||
| 621 | (info) <- processAsync data | ||
| 622 | check info | ||
| 623 | print result, msg | ||
| 624 | ``` | ||
| 625 | <YueDisplay> | ||
| 626 | <pre> | ||
| 627 | result, msg = do | ||
| 628 | (data) <- readAsync "filename.txt" | ||
| 629 | print data | ||
| 630 | (info) <- processAsync data | ||
| 631 | check info | ||
| 632 | print result, msg | ||
| 633 | </pre> | ||
| 634 | </YueDisplay> | ||
| 635 | |||
| 636 | ### Nil Coalescing | 574 | ### Nil Coalescing |
| 637 | 575 | ||
| 638 | The nil-coalescing operator **??** returns the value of its left-hand operand if it isn't **nil**; otherwise, it evaluates the right-hand operand and returns its result. The **??** operator doesn't evaluate its right-hand operand if the left-hand operand evaluates to non-nil. | 576 | The nil-coalescing operator **??** returns the value of its left-hand operand if it isn't **nil**; otherwise, it evaluates the right-hand operand and returns its result. The **??** operator doesn't evaluate its right-hand operand if the left-hand operand evaluates to non-nil. |
| @@ -1655,6 +1593,68 @@ if func 1, 2, 3, | |||
| 1655 | </pre> | 1593 | </pre> |
| 1656 | </YueDisplay> | 1594 | </YueDisplay> |
| 1657 | 1595 | ||
| 1596 | ## Backcalls | ||
| 1597 | |||
| 1598 | Backcalls are used for unnesting callbacks. They are defined using arrows pointed to the left as the last parameter by default filling in a function call. All the syntax is mostly the same as regular arrow functions except that it is just pointing the other way and the function body does not require indent. | ||
| 1599 | |||
| 1600 | ```moonscript | ||
| 1601 | <- f | ||
| 1602 | print "hello" | ||
| 1603 | ``` | ||
| 1604 | <YueDisplay> | ||
| 1605 | <pre> | ||
| 1606 | <- f | ||
| 1607 | print "hello" | ||
| 1608 | </pre> | ||
| 1609 | </YueDisplay> | ||
| 1610 | |||
| 1611 | Fat arrow functions are also available. | ||
| 1612 | |||
| 1613 | ```moonscript | ||
| 1614 | <= f | ||
| 1615 | print @value | ||
| 1616 | ``` | ||
| 1617 | <YueDisplay> | ||
| 1618 | <pre> | ||
| 1619 | <= f | ||
| 1620 | print @value | ||
| 1621 | </pre> | ||
| 1622 | </YueDisplay> | ||
| 1623 | |||
| 1624 | You can specify a placeholder for where you want the backcall function to go as a parameter. | ||
| 1625 | |||
| 1626 | ```moonscript | ||
| 1627 | (x) <- map _, {1, 2, 3} | ||
| 1628 | x * 2 | ||
| 1629 | ``` | ||
| 1630 | <YueDisplay> | ||
| 1631 | <pre> | ||
| 1632 | (x) <- map _, {1, 2, 3} | ||
| 1633 | x * 2 | ||
| 1634 | </pre> | ||
| 1635 | </YueDisplay> | ||
| 1636 | |||
| 1637 | If you wish to have further code after your backcalls, you can set them aside with a do statement. | ||
| 1638 | |||
| 1639 | ```moonscript | ||
| 1640 | result, msg = do | ||
| 1641 | (data) <- readAsync "filename.txt" | ||
| 1642 | print data | ||
| 1643 | (info) <- processAsync data | ||
| 1644 | check info | ||
| 1645 | print result, msg | ||
| 1646 | ``` | ||
| 1647 | <YueDisplay> | ||
| 1648 | <pre> | ||
| 1649 | result, msg = do | ||
| 1650 | (data) <- readAsync "filename.txt" | ||
| 1651 | print data | ||
| 1652 | (info) <- processAsync data | ||
| 1653 | check info | ||
| 1654 | print result, msg | ||
| 1655 | </pre> | ||
| 1656 | </YueDisplay> | ||
| 1657 | |||
| 1658 | ## Table Literals | 1658 | ## Table Literals |
| 1659 | 1659 | ||
| 1660 | Like in Lua, tables are delimited in curly braces. | 1660 | Like in Lua, tables are delimited in curly braces. |
| @@ -2889,10 +2889,6 @@ assert y.__class.__parent ~= X -- X is not parent of Y | |||
| 2889 | </pre> | 2889 | </pre> |
| 2890 | </YueDisplay> | 2890 | </YueDisplay> |
| 2891 | 2891 | ||
| 2892 | ::: warning NOTICE | ||
| 2893 | The rest of the document is describing mostly the same syntax taken from Moonscript. So you may as well refer to the [Moonscript Reference](http://moonscript.org/reference) to get the same explanation. | ||
| 2894 | ::: | ||
| 2895 | |||
| 2896 | ## With Statement | 2892 | ## With Statement |
| 2897 | 2893 | ||
| 2898 | A common pattern involving the creation of an object is calling a series of functions and setting a series of properties immediately after creating it. | 2894 | A common pattern involving the creation of an object is calling a series of functions and setting a series of properties immediately after creating it. |
diff --git a/doc/package.json b/doc/package.json index d484ef9..0784500 100755 --- a/doc/package.json +++ b/doc/package.json | |||
| @@ -19,7 +19,7 @@ | |||
| 19 | "vuepress": "^1.3.1" | 19 | "vuepress": "^1.3.1" |
| 20 | }, | 20 | }, |
| 21 | "dependencies": { | 21 | "dependencies": { |
| 22 | "vue-js-modal": "^2.0.0-rc.6", | 22 | "vue-js-modal": "^2.0.1", |
| 23 | "vue-prism-editor": "^1.2.2" | 23 | "vue-prism-editor": "^1.2.2" |
| 24 | } | 24 | } |
| 25 | } | 25 | } |
