Calling a function of the opener window

It is possible, using JavaScript, to call a function pertaining to the opener window, that is the window that, calling, opened the current window. The code to use is the following:

if (window.opener) {

First it checks if the opener window is still open. In this case, it closes the current window and call the foo function on the opener window.