Here is an example of the code you should use in your plugin init.php file if you need this variable to be global, or in a specific component:
function foo_js_declarations( $e )
{
OW::getDocument()->addOnloadScript("window.BASE_URL=" . json_encode(OW_URL_HOME));
}
OW::getEventManager()->bind(OW_EventManager::ON_FINALIZE, 'foo_js_declarations');