在promise中想要接收数据那就的在jsonp的回调函数将其推向已决状态也就是resolve,也可是说jsonp的回调函数就是为啦将promise推向已决阶段
    案例演示

    1. function jsonp(url, cd) {
    2. return new Promise(resolve => {
    3. let script = document.createElement('script');
    4. if (url.includes("?")) {
    5. url += "&callback=" + cd
    6. } else {
    7. url += "?callback=" + cd;
    8. }
    9. script.src = url;
    10. window[cd] = resp => {
    11. delete window[cd]
    12. document.head.removeChild(script)
    13. resolve(resp)
    14. }
    15. document.head.appendChild(script)
    16. })
    17. }
    18. jsonp("http://developer.duyiedu.com/edu/testJsonp","aaa").then(resp =>{
    19. console.log(resp)
    20. })