收藏
回答

有没有人知道微信小程序js中的函数怎么继承

    这几天又遇到一个问题,就是不知道微信小程序js文件中的函数之间能否继承呢,哪有具体的例子。就是我想在一个function中使用另一个function中的变量。不知道是否可以?求好心人赐教  ^_^不胜感激。

回答关注问题邀请回答
收藏

1 个回答

  • 卢霄霄
    卢霄霄
    2018-10-11

    我这个用的少。。不知道你是不是这个意思

    function f1(){

        this.name = "luxiaoxiao"

    }

    function f2(){

        let instance = new f1()

        console.log(instance.name)

    }

    f2()


    2018-10-11
    有用 1
    回复 5
    • bulabulabula
      bulabulabula
      2018-10-11

          还不知道你是小哥哥还是小姐姐,不过真的谢谢啊,几次给我帮忙。


          举个例子,我现在就是想在函数son中调用函数chooselocation中的变量。刚才试了你说的方法,他报错说son函数中的chooselocation未定义。我也尝试了https://www.hishop.com.cn/xiaocx/show_36812.html  中的方法,也不行     o(╥﹏╥)o


      chooselocation: function (e) {

          var that = this

          wx.chooseLocation({

              success: function (res) {

                  that.setData({

                      location: {

                          latitude: res.latitude,

                          longitude: res.longitude,

                          name: res.name

                      }

                  })

              },

              fail: function (res) {

              },

              complete: function (res) {

              }

          })

      },


      son: function (e) {

          var ww = new chooselocation()

          console.log(ww.name)


      },





      2018-10-11
      回复
    • 卢霄霄
      卢霄霄
      2018-10-11回复bulabulabula

      你这样的啊。。你son里直接 this.data.location.name就可以了啊

      2018-10-11
      1
      回复
    • bulabulabula
      bulabulabula
      2018-10-11回复卢霄霄

      果然是  o(╥﹏╥)o  谢谢啦

      2018-10-11
      回复
    • 卢霄霄
      卢霄霄
      2018-10-11回复bulabulabula

      对不起 我是男的

      2018-10-11
      回复
    • bulabulabula
      bulabulabula
      2018-10-11回复卢霄霄

      没区别 哈哈

      2018-10-11
      回复
登录 后发表内容