window對象
window對象表示當前的瀏覽器窗口。
window對象的成員屬性就是全局屬性。
window對象的成員方法就是全局方法。
全局屬性
JSON
document Document對象
console Console
screen Screen
location Location
history History
navigator Navigator
Storage
localStorage HTML5 本地存儲
sessionStorage
closed 是否關(guān)閉
parent 父窗口
self 當前窗口自己,等價于window。
innerHeight 文檔顯示區(qū)的高度
innerWidth 寬度
outerHeight 窗口的外部高度(包含工具條和滾動條)
outerWidth 外部寬度
全局方法
三種彈出框
alert(?message) 警告框。無返回值|返回值為undefined。
confirm(?message) 確認框。返回值為boolean類型(true或false)。
prompt(?message, ?defaultValue) 提示框。返回值為string類型或為null。
定時
setTimeout(handler, ?timeout, ...arguments) 設置超時時間
clearTimeout(?handle)
setInterval(handler, ?timeout, ...arguments) 設置間隔時間
clearInterval(?handle)
字符串編碼及解碼
escape(html) 對HTML代碼|漢字進行編碼(編碼為Unicode,格式:\uxxxx)
unescape(string) 對Unicode字符串進行解碼|對漢字直接返回。
window.escape("你好")
"%u4F60%u597D"
window.unescape("%u4F60%u597D")
"你好"
window.unescape("你好")
"你好"
Base64編碼及解碼
btoa(asciiStr) 對傳入的英文字符串進行Base64編碼。
atob(base64Str) 對經(jīng)過Base64編碼的字符串進行解碼,信息還原。
btoa("Hello World")
"SGVsbG8gV29ybGQ="
atob("SGVsbG8gV29ybGQ=")
"Hello World"
URI編碼及解碼
encodeURI(uri) 編碼URI。
decodeURI(encodedURI) 解碼經(jīng)過編碼的URI。
encodeURIComponent(uriComponent) 對uri組件進行編碼
decodeURIComponent(encodedURIComponent) 對經(jīng)過編碼的url組件進行組件解碼。
ES6新增數(shù)組方法
查找
find()
查找數(shù)組中符合條件的元素
findIndex()
查找數(shù)組中符合條件的元素的下標
flat(n)
扁平化數(shù)組 n 是扁平的層級
includes(el)查找數(shù)組是否包含el元素
fill(value,start,end)
填充數(shù)組value 填充值,start填充開始位置,end填充的結(jié)束位置
copyWithin(start,start,end)
從數(shù)組中拷貝內(nèi)容替換
rsart 替換開始的位置 start拷貝開始,end拷貝結(jié)束
函數(shù)的簡寫
for of
ES6 的新的遍歷方法
可遍歷的對象 Set Map Array String
可迭代的方法
keys() 鍵的集合
values()值的集合