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,20 +80,28 @@ 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
|
||||
function public_func
|
||||
`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
|
||||
function private_func
|
||||
# ...
|
||||
functions -e private_func
|
||||
end
|
||||
end
|
||||
```
|
||||
end
|
||||
```
|
||||
|
||||
+ Use blocks
|
||||
|
||||
### Blocks
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user