Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS 随记 #128

Open
dlrandy opened this issue Aug 2, 2019 · 2 comments
Open

JS 随记 #128

dlrandy opened this issue Aug 2, 2019 · 2 comments

Comments

@dlrandy
Copy link
Owner

dlrandy commented Aug 2, 2019

字符串转数组的方法:
spread
Array.from
Array.prototype.slice.call
str.split

slice 是如何工作的?
它会将数组或者类数组对象统统作为数组来处理,正常的执行slice功能

@dlrandy
Copy link
Owner Author

dlrandy commented Aug 9, 2019

iframe communication
跨域的情况:
1,不能够直接通过contentDocument调用方法

同域的情况:
1,sharedworker
2,on localStorage
3,直接通过document的访问,或者触发自定义事件
4,

不管跨域与否,都是可以监听iframe的onload事件的。

对于iframe来说 onload前后的document是不一样的
https://stackoverflow.com/questions/9153445/how-to-communicate-between-iframe-and-the-parent-site

https://javascript.info/cross-window-communication

@dlrandy
Copy link
Owner Author

dlrandy commented Sep 4, 2019

function requestWithRetry(url, reteyTimes, ...args) {
let promise = new Promise((resolve, reject) => {
let times = 1;
retryTimes = reteyTimes || times;

function exePromise() {
  fetch(url, { ...args }).then(res => res.json)
  .then(json => resolve(json)).catch(err => {
    if(times++ >= retryTimes){
    return reject(err)
    }
    return exePromise();
  });
}

exePromise();

});
return promise;
}

requestWithRetry('https://sdfsdf.com', 4)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant