From eb48c686a7ab5bd3f3f3a8628ed0423872a932c6 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Mon, 21 Aug 2023 16:52:31 +0800 Subject: fix issue #146. --- doc/docs/doc/README.md | 52 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) (limited to 'doc') diff --git a/doc/docs/doc/README.md b/doc/docs/doc/README.md index 7e4aa22..fbf7e50 100755 --- a/doc/docs/doc/README.md +++ b/doc/docs/doc/README.md @@ -43,7 +43,7 @@ apple = p apple.color, apple. if apple.<>? -- js-like export syntax -export yuescript = "ζœˆδΉ‹θ„šζœ¬" +export πŸŒ› = "ζœˆδΉ‹θ„šζœ¬" ```
@@ -75,7 +75,7 @@ apple =
 p apple.color, apple.<index> if apple.<>?
 
 -- js-like export syntax
-export yuescript = "ζœˆδΉ‹θ„šζœ¬"
+export πŸŒ› = "ζœˆδΉ‹θ„šζœ¬"
 
@@ -3027,6 +3027,54 @@ some_instance_method = (...)=> @@ ... +### Constructor Property Promotion + +To reduce the boilerplate code for definition of simple value objects. You can write a simple class like: + +```moonscript +class Something + new: (@foo, @bar, @@biz, @@baz) => + +-- Which is short for + +class Something + new: (foo, bar, biz, baz) => + @foo = foo + @bar = bar + @@biz = biz + @@baz = baz +``` + +
+class Something
+  new: (@foo, @bar, @@biz, @@baz) =>
+
+-- Which is short for
+
+class Something
+  new: (foo, bar, biz, baz) =>
+    @foo = foo
+    @bar = bar
+    @@biz = biz
+    @@baz = baz
+
+
+ +You can also use this syntax for a common function to initialize a object's fields. + +```moonscript +new = (@fieldA, @fieldB)=> @ +obj = new {}, 123, "abc" +print obj +``` + +
+new = (@fieldA, @fieldB)=> @
+obj = new {}, 123, "abc"
+print obj
+
+
+ ### Class Expressions The class syntax can also be used as an expression which can be assigned to a variable or explicitly returned. -- cgit v1.2.3-55-g6feb