called function A(args) calls a function B() which then calls a function A(args), How to do that?
Posted
by Ken
on Stack Overflow
See other posts from Stack Overflow
or by Ken
Published on 2010-03-20T15:47:56Z
Indexed on
2010/03/20
15:51 UTC
Read the original article
Hit count: 344
JavaScript
|functions
See example:
<!DOCTYPE html>
<html>
<head>
<title>language</title>
<script type="text/javascript" src="http://www.google.com/jsapi">
</script>
</head>
<body>
<div id="language"></div>
<script type="text/javascript">
var loaded = false;
function load_api() {
google.load("language", "1", {
"nocss": true,
"callback": function() {
loaded = true;
callback_to_caller(with_caller_agruments);
// how to call a function (with the same arguments) which called load_api() ???
// case 1 should be: detect_language('testing');
// case 2 should be: translate('some text');
}
});
}
function detect_language(text) {
if (!loaded) {
load_api();
} else {
// let's continue... believe that google.language is loaded & ready to use
google.language.detect(text, function(result) {
if (!result.error && result.language) {
document.getElementById('language').innerHTML = result.language;
}
});
}
}
function translate(text) {
if (!loaded) {
load_api();
} else {
// let's continue...
}
}
detect_language('testing'); // case 1
translate('some text'); // case 2
</script>
</body>
</html>
© Stack Overflow or respective owner