js中函数多参数的简化

 1

function createPerson({ name = "Unknown", age = 0, gender = "Unknown", ...other }) {  
  return { name, age, gender, other };  
}  
  
const person = createPerson({ name: "John", age: 30, gender: "male", occupation: "developer", hobbies: ["reading", "traveling"] });  
console.log(person)

2

 /**
     * @Event 方法
     * @description: 更换点位图标、并将点击的点位移动到地图中心
     * @params: latLog:经纬度(非字符串) { lat: e.latitude, lng: e.longitude }
     * @params: data: 传递给选中图标点击出现的弹窗的数据(passData.data) data:{data: {}, type: "视频监控"}
     * @param: type: 4 视频监控  2 信息屏  3 路口  1 停车场
     * @param: imgType: 图片名称Choose.png
     * */
    setMapCenter(params) {
      const { latLog, data, imgType, type } = params
      console.log(latLog, data, imgType, type, "setMapCenter");
      this.map.panTo(latLog);
      this.removeSearchMarker();
      var markerIcon = "";
      markerIcon = L.divIcon({
        className: "markerBox",
        html: `
`, iconSize: [40, 40], }); this.searchMarker = new L.Marker(latLog, { icon: markerIcon }); this.map.addLayer(this.searchMarker); this.searchMarker.setZIndexOffset(10000); // 设置层级以防被覆盖 let that = this; this.searchMarker.on("click", function () { /* 选中后的图标点击事件 */ if (type == 1) { let passData = { data: data.data, type: "停车场", }; /* 打开停车场详情的弹窗 */ that.$refs.parkingDialog.showDialog(passData); } if (type == 2) { let passData = { data: data.data, type: "信息屏", }; /* 打开信息屏详情的弹窗 */ that.$refs.screenDialog.showDialog(passData); } if (type == 3) { let passData = { data: data.data, type: "路口", }; /* 打开路口详情的弹窗 */ that.$refs.intersectionDialog.showDialog(passData); } if (type == 4) { let passData = { data: data.data, type: "视频监控", }; /* 打开视频监控详情的弹窗 */ that.$refs.monitorDialog.showDialog(passData); } }); }, let obj = { latLog: { lat: parseFloat(item.latitude), lng: parseFloat(item.longitude), }, data: { data: { ...item, id: item.searchId, code: item.searchCode }, type: typeList.find(e => e.interfaceType === item.searchType).type }, imgType: typeList.find(e => e.interfaceType === item.searchType).imgType + "Choose.png", type: typeList.find(e => e.interfaceType === item.searchType).searchType } this.$emit("setMapCenter", obj)

你可能感兴趣的:(JS基础,javascript,前端,vue.js)