One problem that you will discover when you start putting user interface elements into an object is that you may run into trouble when you try to call a method (a method is a function in your class) within your class when input occurs. For instance, if you try to have your Button’s mousePressed function call a method you will notice it does not quite work as you expect. This is because it binds the callback to the Classes function definition but not to the Object.

To solve this problem, you need to do a technique that will bind the callback to the object’s method.

function bind(toObject, methodName){
    return function(){toObject[methodName]()}
}