在对象中使用数组方法,用数字取的属性名会被默认为下标。
e.g.
//在数组中,push是向数组末尾(arr[length])添加数据
var obj = {
'e':'a',
't':'b',
'length':4,
push:Array.prototype.push
};
obj.push('c'); //VM129:8 {4: "c", e: "a", t: "b", length: 5, push: ƒ}
var obj = {
'4':'a',
't':'b',
'length':4,
push:Array.prototype.push
};
obj.push('c'); //VM141:8 {4: "c", t: "b", length: 5, push: ƒ}
var obj = {
'e':'a',
'4':'b',
'length':4,
push:Array.prototype.push
};
obj.push('c'); //VM151:8 {4: "c", e: "a", length: 5, push: ƒ}
其他笔记
1、变量的声明会被提前到作用域的顶部,赋值保留在原地。
2、函数声明会整个函数被提前。
3、函数作为赋值给变量时只有变量会被提前,函数不会被提前。
4、同名的函数和变量,函数的提前在变量的前面,也就是函数的优先级大于变量的。
网友评论