-
Notifications
You must be signed in to change notification settings - Fork 0
Functions inside functions!
Julius Paffrath edited this page Dec 8, 2016
·
3 revisions
jask supports a very cool feature called inside function defines. This allows you to define a function inside a function! See the following code:
function myFunction()
function insideFunction()
printLine("I am a function defined inside!")
end
insideFunction()
end
The defined function insideFunction lives only inside myFunction and can't be called outside. In addition insideFunction can't access variables through the access operator outside of the wrapping function. To avoid this, have a look at the following code:
store 100 in outsideVar
function myFunction()
store !outsideVar in insideVar
function insideFunction()
printLine(!insideVar)
end
insideFunction()
end
This looks a little bit puzzling but let me explain it:
- first, the variable outsideVar is stored with the value 100
- in myFunction a new variable is stored called insideVar and get's the value from outsideVar
- in the end insideFunction access insideVar through the access operator
- Home
- Getting started
- Control flow
- Functions
- List variables in jask
- Dictionary variables in jask
- Structs in jask
- Convert variables
- Internal Functions
- The access operator
- Callbacks in jask
- Modules
- Internal Modules
- The jask standard library jcore
- Using CMD arguments in jask
- Nested function calls
- Functions inside functions!
- Modules inside functions!
- Performance comparison of loops