Awet,
First just to be sure you know. AGOL version of WAB does not allow for adding or using custom widget. WAB Dev edition is the only one that will allow you to add custom widgets and themes.
Now as far as your question. A function that returns a value is simple and most all functions can be called recursively. So a WAB widget function would look like this:
myFunction: function(inputVal){
var newVal;
newVal = inputVal + 3;
return newVal;
},
you can look at otb widgets in the widgets folder for best practice coding and ideas. Widget development is not exactly like standard JS coding and be sure to understand AMD coding style.
There are widget development walkthroughs on the WEB Dev site: Create a custom in-panel widget—Web AppBuilder for ArcGIS (Developer Edition) | ArcGIS for Developer...
And dojo templated widget coding Creating Template-based Widgets - Archived Tutorial - Dojo Toolkit