作用域
var a=b=10;
(function f(){
var a=b=11;
})()
console.log(a); //10
console.log(b); //11
var a=1
function fn(){
var a=2
b=3
}
fn()
console.log(a) //1
console.log(b) //3
var a=1
let a=2
console.log(a)
//SyntaxError: Identifier 'a' has already been declared
原型链
function tree(){
}
tree.prototype.add=function(){
this.leaf++
}
tree.prototype.leaf=1
var t1=new tree()
var t2=new tree()
console.log(t1.leaf) //1
console.log(t2.leaf) //1
t1.add()
console.log(t1.leaf) //2
console.log(t2.leaf) //1
Promise和setTimeout输出顺序
var r1 = new Promise(function(res, rej) {
var r2 = new Promise(function(res, rej) {
setTimeout(() => {
console.log(1)
}, 0)
res(2)
console.log(3)
})
r2.then(i => {
console.log(i)
})
res(4)
console.log(5)
})
r1.then(i => {
console.log(i)
})
console.log('6')
// 3 5 6 2 4 1