javascript - Google Plus API onload callback behavior -


i trying load google plus api within function in object, like:

var myobject = {     initialize : function(options) {         window.___gcfg = {           parsetags : 'explicit'         };            (function() {             var po = document.createelement('script');             po.type = 'text/javascript';             po.async = true;             po.src = 'https://apis.google.com/js/plusone.js?onload=onloadgoogleplus';             var s = document.getelementsbytagname('script')[0];             s.parentnode.insertbefore(po, s);         })();          ... 

then have onloadgoogleplus() defined outside object, regular global function.

now, if execute anonymous function load gapi within object, using initialize() function callback not called. in case "this" keyword points object.

but, if following (which makes "this" keyword point "window"), work:

initialize : function(options) {     window.___gcfg = {       parsetags : 'explicit'     };        settimeout(function() {         (function() {             var po = document.createelement('script');             po.type = 'text/javascript';             po.async = true;             po.src = 'https://apis.google.com/js/plusone.js?onload=onloadgoogleplus';             var s = document.getelementsbytagname('script')[0];             s.parentnode.insertbefore(po, s);         })();     }, 0); ... 

i confused, related "this" keyword @ all? because calling function myobject.initialize() firefox's console makes work (my "onload" callback executed), doesn't otherwise, unless use settimeout(..., 0)


Comments

Popular posts from this blog

mysql - java.sql.SQLException Parameter index out of range (1 > number of parameters, which is 0) -

c - ALSA programming: how to stop immediately -