zoukankan      html  css  js  c++  java
  • of 循环 改变 对象值 对const的理解 对象的字面量 计算属性

    const arr = [{a:23,b:34},{a:123,b:134}]
    console.log(arr)
    for (let v of arr){
    console.log(v)
    const old = v.a
    v.a=old*old
    console.log(v)
    }
    console.log(arr)

    arr已经发生了改变

    场景

    微信小程序开发

    对后端接口的时间戳格式数据处理

    mpBMCwepysrcutilsutil.js
    
    
    const timestampSecondsToTime = (tmp) => {
      const t = function (i) {
        return (i < 10 ? '0' + (i) : i)
      }
      const date = new Date(tmp * 1000)
      const Y = date.getFullYear() + '-'
      const M = t(date.getMonth() + 1) + '-'
      const D = t(date.getDate()) + ' '
      const h = t(date.getHours()) + ':'
      const m = t(date.getMinutes()) + ':'
      const s = t(date.getSeconds())
      return Y + M + D + h + m + s
    }
    const convertArrObjListTimestamp = (arr, timestampKey) => {
      for (let v of arr) {
        const old = v[timestampKey]
        v[timestampKey] = timestampSecondsToTime(old)
      }
      return arr
    }
    export default {
      isInClosedInterval,
      isLogined,
      isMobilePhoneNum,
      delAllNonPrintableCharacter,
      convertArrObjListTimestamp
    }
    
    
    mpBMCwepysrcpagescloundAd.vue
    
    
       async getFeedData() {
          if (this.apiRes.AdKWPublished !== undefined) {
            if (this.pagination.total === this.apiRes.AdKWPublished.length) {
              wx.showToast({
                title: '亲我有底线',
                icon: 'loading',
                duration: 1500
              })
              return
            }
          }
          const q = {
            query: {
              uid: this.$parent.UID.uid,
              page: this.pagination.from,
              size: this.pagination.size
            }
          }
          const r = await api.getAdKWPublished(q)
          if (r === false) {
            return
          } else if (r.data.status !== 1) {
            wx.showToast({
              title: '亲暂无更多',
              icon: 'loading',
              duration: 1500
            })
            return
          }
          let arr = r.data.data
          arr = util.convertArrObjListTimestamp(arr, 'create_time')
          this.apiRes.AdKWPublished = this.apiRes.AdKWPublished ? this.apiRes.AdKWPublished.concat(arr) : arr
          this.pagination.total = r.data.count
          this.pagination.from += 1
          this.$apply()
        }
    

      

    方法: 对可读的时间格式的多样性扩展性

     暂时没有满足开闭原则

    const a={
    false :'123',
    v:567
    }
    const b=false
    a[b]

  • 相关阅读:
    cocos2d
    Java中== equals hashcode浅析[转]
    javamail发送邮件的简单实例[转]
    跨平台 游戏 引擎
    7 个漂亮的 JavaScript 的时间轴组件 [转]
    Java中的equals学习小结 [转]
    javamail gmail
    JavaMai——邮箱验证用户注册
    daomain
    oDesk Exam
  • 原文地址:https://www.cnblogs.com/rsapaper/p/9721497.html
Copyright © 2011-2022 走看看