aboutsummaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2022-08-16 15:46:32 +0800
committerLi Jin <dragon-fly@qq.com>2022-08-16 15:46:32 +0800
commita4d4893c77f9c48dedc88472a2e418bfd65e33a1 (patch)
treeb40dc41ef56c483797e14d269ee164d1c719757e /doc
parent5375fd872490eaef7499e344585476edf58005d8 (diff)
downloadyuescript-a4d4893c77f9c48dedc88472a2e418bfd65e33a1.tar.gz
yuescript-a4d4893c77f9c48dedc88472a2e418bfd65e33a1.tar.bz2
yuescript-a4d4893c77f9c48dedc88472a2e418bfd65e33a1.zip
update docs.
Diffstat (limited to 'doc')
-rwxr-xr-xdoc/docs/doc/README.md128
-rwxr-xr-xdoc/package.json2
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
576Backcalls 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
580print "hello"
581```
582<YueDisplay>
583<pre>
584<- f
585print "hello"
586</pre>
587</YueDisplay>
588
589Fat arrow functions are also available.
590
591```moonscript
592<= f
593print @value
594```
595<YueDisplay>
596<pre>
597<= f
598print @value
599</pre>
600</YueDisplay>
601
602You 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}
606x * 2
607```
608<YueDisplay>
609<pre>
610(x) <- map _, {1, 2, 3}
611x * 2
612</pre>
613</YueDisplay>
614
615If you wish to have further code after your backcalls, you can set them aside with a do statement.
616
617```moonscript
618result, msg = do
619 (data) <- readAsync "filename.txt"
620 print data
621 (info) <- processAsync data
622 check info
623print result, msg
624```
625<YueDisplay>
626<pre>
627result, msg = do
628 (data) <- readAsync "filename.txt"
629 print data
630 (info) <- processAsync data
631 check info
632print result, msg
633</pre>
634</YueDisplay>
635
636### Nil Coalescing 574### Nil Coalescing
637 575
638The 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. 576The 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
1598Backcalls 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
1602print "hello"
1603```
1604<YueDisplay>
1605<pre>
1606<- f
1607print "hello"
1608</pre>
1609</YueDisplay>
1610
1611Fat arrow functions are also available.
1612
1613```moonscript
1614<= f
1615print @value
1616```
1617<YueDisplay>
1618<pre>
1619<= f
1620print @value
1621</pre>
1622</YueDisplay>
1623
1624You 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}
1628x * 2
1629```
1630<YueDisplay>
1631<pre>
1632(x) <- map _, {1, 2, 3}
1633x * 2
1634</pre>
1635</YueDisplay>
1636
1637If you wish to have further code after your backcalls, you can set them aside with a do statement.
1638
1639```moonscript
1640result, msg = do
1641 (data) <- readAsync "filename.txt"
1642 print data
1643 (info) <- processAsync data
1644 check info
1645print result, msg
1646```
1647<YueDisplay>
1648<pre>
1649result, msg = do
1650 (data) <- readAsync "filename.txt"
1651 print data
1652 (info) <- processAsync data
1653 check info
1654print result, msg
1655</pre>
1656</YueDisplay>
1657
1658## Table Literals 1658## Table Literals
1659 1659
1660Like in Lua, tables are delimited in curly braces. 1660Like 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
2893The 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
2898A common pattern involving the creation of an object is calling a series of functions and setting a series of properties immediately after creating it. 2894A 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}