How to make specific of controller bar button connect to a function

I follow the script and creat a button in the controller bar successfully!
Now I want to know how to make the button connect to a function ?