Functions defined during a bash session are only available in that session. You cannot define a function on the command line, and then expect to have it available in a Bash script you execute, or in another user's bash session. You would need to include the function definition in the script, and have the other user load your function first.
Functions that use curly brackets, {...}, for the function body operate in the current process of the shell. This allows you to have functions that can change your current working directory, such as cd shortcuts, to view and set variables for the current active shell, or to set shell runtime options, such as -x.
This means that variable assignments aren't local to functions; they're visible outside it, after the function has run:
bash$ func1() { foo=bar ; printf '%s\n' "$foo" ; }
bash$ func1
foo
bash$ declare -p foo
declare -- foo="bar"
If you want to set variables that are only visible inside the function body, you can use the local Bash keyword to declare the variable as being local to the function before you set it:
bash$ func2() { local baz ; baz=quux ; printf '%s\n' "$baz" ; }
bash$ func2
quux
bash$ declare -p baz
-bash: declare: baz: not found
If you want to run a function so that it doesn't affect your current shell at all, including shell options, positional parameters, and current working directory, one method is to run it with a subshell body instead, by using parentheses instead of curly brackets. Consider these two functions, etc1 and etc2:
bash$ etc1() { cd /etc ; }
bash$ etc2() ( cd /etc )
Notice that the function body for etc2 is surrounded with parentheses and not curly brackets. Also note that for this function type, a control character such as ; is not required after the last command.
If we run each of these functions, we can see that the first one changes the current directory of our shell, but the second one does not:
bash$ cd ~ bash$ etc1 bash$ pwd /etc bash$ cd ~ bash$ etc2 bash$ pwd /home/bashuser
This is because the directory change in the etc2 function took place in a subshell; its parent process, our interactive shell, did not have its own working directory changed.