mirror of
https://github.com/oh-my-fish/oh-my-fish.git
synced 2024-11-22 22:03:53 +08:00
add a Private Functions section
This commit is contained in:
parent
0767b2a72f
commit
87d88f702e
|
@ -80,11 +80,17 @@ function greet -a message -d "Display a greeting message"
|
|||
end
|
||||
```
|
||||
|
||||
In order to avoid name collision, name your functions using a prefix based on the name of your package. For example, if you are writing a `ninja` package use `ninja.function_name`.
|
||||
In order to avoid name collisions, use a prefix based on the name of your package. For example, if you are writing a `ninja` package use `ninja.function_name`.
|
||||
|
||||
`fish` does not have private functions, so in order to avoid polluting the global namespace, use double underscore before your function name. For example, if you are writing a `ninja` plugin using `__ninja.function_name`.
|
||||
|
||||
Note that it's still possible to mimic private functions in `fish` by deleting the function before returning using `functions -e function_name`
|
||||
### Private Functions
|
||||
|
||||
`fish` does not have private functions, so in order to avoid polluting the global namespace you have a few options:
|
||||
|
||||
|
||||
+ Use double underscore before your function name. For example, if you are writing a `ninja` package using `__ninja.function_name`.
|
||||
|
||||
+ Delete the function before returning using `functions -e function_name`
|
||||
|
||||
```fish
|
||||
function public_func
|
||||
|
@ -95,6 +101,8 @@ function public_func
|
|||
end
|
||||
```
|
||||
|
||||
+ Use blocks
|
||||
|
||||
### Blocks
|
||||
|
||||
Blocks allow you to write code resembling macro expressions composed of smaller blocks without relying on variables.
|
||||
|
|
Loading…
Reference in New Issue
Block a user