Skip to content

Instantly share code, notes, and snippets.

@imyelo
Created March 24, 2014 09:49
Show Gist options
  • Save imyelo/9737368 to your computer and use it in GitHub Desktop.
Save imyelo/9737368 to your computer and use it in GitHub Desktop.
better WeixinJSBridgeReady
window.whenWechatReady = (function () {
var isReady = false;
var tasks = [];
var when = function (callback) {
if (isReady) {
return callback();
}
return tasks.push(callback);
};
document.addEventListener('WeixinJSBridgeReady', function () {
isReady = true;
while (tasks.length > 0) {
tasks.shift()();
}
});
return when;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment