<!-- <script>
// const 声明一个只读的常量, 只能读取——基本类型 初始化的时候必须给值 (另一种是引用类型) 栈里
const abc = 111;
// abc = 222; // 报错
const abcarray = {
name: 'kkk',
}
abcarray.name = 'req' //这是可行的 引用类型 堆里
//-----------------------------箭头=> 不能当做 构造函数 不能new 没有原型对象 不能用arguments-----------------------------------
let f1 = function (v) {
return v;
}
f1(1234);
let f2 = v => v;
f2(2345);
// let ice1 = new f2('ice', 10); //: 报错 f2 is not a constructor 不能当做 构造函数
function f3(name, age) {
this.name = name;
this.age = age;
} //构造函数用来生成对象的模板
f3.prototype.sex = '1'; //没有原型对象
let ice = new f3('ice', 10);
let jb = new f3('jb', 20);
console.log(ice)
function f4() {
console.log(arguments) // 不能用arguments 参数集合
console.log(arguments[1])
}
f4(1, 2, 3, 4, 5, 6);
let f5 = (a, b, ...c) => {
console.log(c) //3,4,5
}; //箭头函数 用rest
f5(1, 2, 3, 4, 5);
//..............................................扩展运算符
function f6(...item) {
console.log(item) //0,1,2,3,4,5,6
}
let arr10 = [1, 2, 3];
let arr20 = [3, 4, 5];
f6(0, ...arr10, ...arr20, ...[6]);
//等价f6(0,1,2,3,4,5,6)
let arr12 = [...arr10, ...arr20];
let o1 = {
id: 1,
name: 'abc'
}
let o2 = {
...o1,
sex: 0
}
//等价
// let o2 = {
// id: 1,
// name: 'abc',
// sex: 0
// }
var str = 'global';
var obj = {
str: 'private',
getstr: function () {
console.log(this.str) //private
}
}
var obj1 = {
str: 'private',
getstr: () => {
console.log(this.str) //箭头函数本身是没有this的,他会去上下文寻找,obj1的上下文找到的是 global 严格模式报错
}
}
obj.getstr();
obj1.getstr();
</script> -->