Created
March 24, 2014 09:49
-
-
Save imyelo/9737368 to your computer and use it in GitHub Desktop.
better WeixinJSBridgeReady
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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