我在 Webkit 上运行以下代码:
var scriptElements = document.scripts;
var scriptUrls = [];
// URL matching
var regexp = /\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/i;
for (var i = 0; i < scriptElements.length; i++) {
element = scriptElements[i];
var urls = element.innerHTML.match(regexp);
console.log('local', urls);
scriptUrls.concat(urls);
console.log('global', scriptUrls);
}
我看到在“本地”之后打印了非空数组,但“全局”始终保持为空数组。这是怎么回事?