require返回值
发布于 6 年前 作者 ming55 2356 次浏览 来自 问答

你好:

我刚学小程序,看了文档觉得有点疑惑,require有时返回对象,有时返回字符串,调用时需要自己先判断对象类型吗?

如:模块化章节:

var common = require(‘common.js’)

Page({

  helloMINA: function() {

    common.sayHello(‘MINA’)

  },

  goodbyeMINA: function() {

    common.sayGoodbye(‘MINA’)

  }

})

上面就返回的时对象object。

但是在behaviors章节,返回是字符串,

如:

var myBehavior = require('my-behavior')

Component({

 behaviors: [myBehavior],  properties: {    myProperty: {      type: String    }  },  data: {    myData: {}  },  attached: function(){},  methods: {    myMethod: function(){}  }})

回到顶部