maxZIndex=function(){return Array.from(document.all).reduce(function(max, i){return Math.max(max, +window.getComputedStyle(i).zIndex || 0)}, 0);}
Array.from(document.all) 我们用 querySelectorAll 形成的是一个类数组结构,但不是数组,不支持数组方法。因此,使用 Array.from 方法,将它转化为真正的数组。
array.reduce(function(total, currentValue, currentIndex, arr), initialValue); reduce完整用法
+window.getComputedStyle(i).zIndex || 0 把auto转为数值,||0 NaN转为0
es6写法
maxZIndex=function(){return [...document.all].reduce((r, e) => Math.max(r, +window.getComputedStyle(e).zIndex || 0), 0);}