学习笔记
作者:oMing
ES6
let 与 var 的区别
let l1
= 1;
let l1
= 2;
var v1
= 1;
var v1
= 2;
console
.log(v1
);
{
var girl
= 'C#'
let boy
= 'unity'
}
console
.log(girl
)
console
.log(boy
)
解构赋值
const F4 = ['unity', 'vue', 'jQuery', 'npm']
let [u
, v
, j
, n
] = F4
console
.log(u
+ ' ' + v
+ ' ' + j
+ ' ' + n
)
const unity
= {
name
: 'unity',
makeGames
: function () {
console
.log('Made with Unity~')
}
}
let { name
, makeGames
} = unity
console
.log(name
+ ' ' + makeGames
)
makeGames()
模板字符串 (方便拼接,可换行)
let action
= `周星驰、
邓超`
console
.log(`${action}是我最喜欢的演员~`)
箭头函数
let commonFun = function () {
console
.log(this.name
)
}
let arrowFun = () => {
console
.log(this.name
)
}
window
.name
= 'oMing'
commonFun()
arrowFun()
let people
= { name
: 'Vue' }
commonFun
.call(people
)
arrowFun
.call(people
)
let div1
= document
.getElementById('div1')
div1
.addEventListener('click', function () {
let self
= this
setTimeout(function(){
self
.style
.background
= 'pink'
},1000)
setTimeout(() => {
this.style
.background
= 'pink'
}, 1000)
})
const arr
= [1, 6, 8, 9, 12]
console
.log(arr
.filter(item
=> item
% 2 == 0))
【…】扩展运算符(将【数组】转换为逗号分隔的【参数序列】)
const arr3
= ['JavaScript', 'google', 'vue']
function web() {
console
.log(arguments
[1])
}
web(...arr3
)
const oVuex
= ['v', 'u', 'e', 'x']
const oVue_cli
= ['c', 'l', 'i']
console
.log([...oVuex
, ...oVue_cli
])
const oVue
= ['v', 'u', 'e']
const oVueClone
= [...oVue
]
let divs
= document
.querySelectorAll('div')
console
.log([...divs
])
function data(a
, b
, ...args
) {
console
.log(a
)
console
.log(b
)
console
.log(args
)
}
data(1, 2, 3, 4, 5, 6)
转载请注明原文地址:https://tech.qufami.com/read-14103.html