A function may create a closure and return it . The following example is a function that returns a function . In some languages , a closure may occur when a function is defined within another function , and the inner function refers to local variables of the outer function .