You're expecting monkey_fur to return language, but in reality, it's the detect callback (which is fired asynchronously, after a request is sent to Google and returned). Anything that is going to depend on the language detection response is going to have to be called from within that callback (i.e., the function you provide google.language.detect())
Jeremy R. Geerdes Effective website design & development Des Moines, IA For more information or a project quote: http://jgeerdes.home.mchsi.com [email protected] If you're in the Des Moines, IA, area, check out Debra Heights Wesleyan Church! On Aug 3, 2010, at 2:52 PM, Dennis wrote: > I have a function that is supposed to return the google detected > language but when I tell my function to return the language and then > console.log the function, the console returns undefined. If I > console.log the language inside the function, it works. > > Any ideas? > > //Doesn't Work > var monkey_fur = function(str) { > google.language.detect(str, function(result) { > if (!result.error) { > var language = 'unknown'; > for (l in google.language.Languages) { > if (google.language.Languages[l] == > result.language) { > language = l; > break; > } > } > return language; > } > }); > } > console.log(monkey_fur(text)); > > //Works > var monkey_fur = function(str) { > google.language.detect(str, function(result) { > if (!result.error) { > var language = 'unknown'; > for (l in google.language.Languages) { > if (google.language.Languages[l] == > result.language) { > language = l; > break; > } > } > console.log(language); > } > }); > } > > -- > You received this message because you are subscribed to the Google Groups > "Google AJAX APIs" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/google-ajax-search-api?hl=en. > -- You received this message because you are subscribed to the Google Groups "Google AJAX APIs" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-ajax-search-api?hl=en.
