var anArray = ['one', 'two', 'three']; for (var i = 0, l = anArray.length; i < l; i++) { setTimeout(function (item) { console.log(item); // logs: one two three }, 1, anArray[i]); }
连接数组而不创建新对象
1 2 3 4
var a = [1, 2, 3]; var b = [4, 5, 6]; Array.prototype.push.apply(a, b); console.log(a); // [1, 2, 3, 4, 5, 6]
页面卸载
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/// ###### 监听页面 隐藏/显示 Start ##### ##### ##### ##### // query current page visibility state: prerender, visible, hidden var pageVisibility = document.visibilityState; // subscribe to visibility change events document.addEventListener('visibilitychange', function() { // fires when user switches tabs, apps, goes to homescreen, etc. if (document.visibilityState == 'hidden') { console.log('hidden...') } // fires when app transitions from prerender, user returns to the app / tab. if (document.visibilityState == 'visible') { console.log('visible...') } }); /// ###### 监听页面 隐藏/显示 End ##### ##### ##### #####