mirror of
https://github.com/leafo/moonscript.git
synced 2025-01-09 00:04:22 +00:00
standalone @ and @@ are aliases for self and self.__class
This commit is contained in:
parent
3a2b92e5d3
commit
d7f8ade88e
@ -864,6 +864,23 @@ described above:
|
|||||||
These expressions are executed after all the properties have been added to the
|
These expressions are executed after all the properties have been added to the
|
||||||
*base*.
|
*base*.
|
||||||
|
|
||||||
|
|
||||||
|
### `@` and `@@` Values
|
||||||
|
|
||||||
|
When `@` and `@@` are prefixed in front of a name they represent, respectively,
|
||||||
|
that name accessed in `self` and `self.__class`.
|
||||||
|
|
||||||
|
If they are used all by themselves, they are aliases for `self` and
|
||||||
|
`self.__class`.
|
||||||
|
|
||||||
|
assert @ == self
|
||||||
|
assert @@ == self.__class
|
||||||
|
|
||||||
|
For example, a quick way to create a new instance of the same class from an
|
||||||
|
instance method using `@@`:
|
||||||
|
|
||||||
|
some_instance_method = (...) => @@ ...
|
||||||
|
|
||||||
## Export Statement
|
## Export Statement
|
||||||
|
|
||||||
Because, by default, all assignments to variables that are not lexically visible will
|
Because, by default, all assignments to variables that are not lexically visible will
|
||||||
|
@ -266,7 +266,10 @@ local build_grammar = wrap_env(function()
|
|||||||
return true
|
return true
|
||||||
end) / trim
|
end) / trim
|
||||||
|
|
||||||
local SelfName = Space * "@" * ("@" * _Name / mark"self_class" + _Name / mark"self")
|
local SelfName = Space * "@" * (
|
||||||
|
"@" * (_Name / mark"self_class" + Cc"self.__class") +
|
||||||
|
_Name / mark"self" + Cc"self")
|
||||||
|
|
||||||
local KeyName = SelfName + Space * _Name
|
local KeyName = SelfName + Space * _Name
|
||||||
|
|
||||||
local Name = SelfName + Name + Space * "..." / trim
|
local Name = SelfName + Name + Space * "..." / trim
|
||||||
|
@ -101,3 +101,17 @@ class ClassMan
|
|||||||
@red: =>
|
@red: =>
|
||||||
|
|
||||||
|
|
||||||
|
x = @
|
||||||
|
y = @@
|
||||||
|
|
||||||
|
@ something
|
||||||
|
|
||||||
|
@@ something
|
||||||
|
|
||||||
|
@ = @ + @ / @
|
||||||
|
|
||||||
|
@ = 343
|
||||||
|
@.hello 2,3,4
|
||||||
|
|
||||||
|
hello[@].world
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user