如你所知,使用html5的API postMessage,我们可以将消息发布到当前页面的iframe,或者到一个新的弹出窗口,但是如果我们像这样编码:
var popwindow = window.open('http://localhost:8080/index2.html');
popwindow.postMessage({
"age": 10
},
'http://localhost:8080/index2.html');
Run Code Online (Sandbox Code Playgroud)
当弹出窗口尚未加载时,我们将无法收到消息,因为我们使用“postMessage”,那么我们如何确保弹出窗口已加载?popwindow.onload
我们不能在当前页面使用,那怎么办呢?
我想知道JavaScript中的forEach是否可以返回,这是我的代码:
var a = [0, 1, 2, 3, 4];
function fn(array) {
array.forEach(function(item) {
if (item === 2) return false;
});
return true;
}
var ans = fn(a);
console.log(ans); // true
Run Code Online (Sandbox Code Playgroud)
我想知道2是否在我的数组中,如果是,返回false,但似乎forEach函数已经循环整个数组并忽略return.
我想知道我是否能得到我想要的答案forEach(我知道我可以得到我想用的(...))?亲爱的朋友,请帮助我,非常感谢!
我知道JavaScript现在有sets,但是我想知道有没有什么东西可以实现multiSet的功能,或者有什么框架有我非常需要的multiset的功能。
或者我必须自己编写代码来研究红黑树?