箭头函数:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
</head>
<body>
<h1>我的第一个 Web 页面</h1>
<p>我的第一个段落。</p>
<script>
let calculate=(op,...data)=>{
if(op === "+"){
let result = 0;
for(let i = 0;i < data.length; i ++){
result += data[i];
}
return result;
}
else if(op === "*"){
let result = 1;
for(let i = 0;i < data.length;i ++){
result *= data[i];
}
return result;
}
}
document.write(Date());
document.write(calculate("+",1,2,3,4,5,6,7));
document.write(calculate("*",1,2,3,4,5,6,7,8,9));
let arr1=[1,2,3,4,5];
let arr2=[...arr1];
console.log([...arr1,...arr2]);
//function sum_arr(...data){
let sum_arr=(...data)=>{
let result=0;
for(let i=0;i<data.length;i++){
result += data[i];
}
return result;
}
console.log(sum_arr(...arr1));
let book = {
title: "杜甫诗集",
price:98
}
let bookdetail = {...book,desc:"a fine book"}
console.log(bookdetail);
let wide=10;
let high=20;
let size={wide,high};
console.log(size);
var car = {
color:"red",
dools:4,
show:function(){
console.log(this.color);
},
dool_num(){
console.log(this.dools);
},
engine:{
type:"elect",
power:20
}
}
let n="mini";
car.show();
car.dool_num();
car["wide"]=wide;
car[n+"car"]=high;
console.log(car);
let {color,dools}=car;
console.log(color);
console.log(dools);
car.wide=22;
({wide}=car);
console.log(wide);
let{color:tcolor}=car;
console.log(tcolor);
let{engine:{type:etype}}=car;
console.log(etype);
let putout=(user,msg)=>`${user} result:${msg}`;
console.log(putout("zhangsan"," pass"));
let creatcar=(color,doors)=>({color:color,doors:doors});
console.log(creatcar("blue",13));
</script>
</body>
</html>
|