全局共享函数的问题
发布于 6 年前 作者 jun64 6044 次浏览 来自 问答

 小程序的全局函数怎么定义啊,比如在common.js 中定义成a:function( ){}报错,定义成a=function(){}不报错 module.exports.a=a,在调用时在页头 var utils = require(’…/…/utils/util.js’),使用utils.a会报没有定义,要怎么做呢

2 回复

module.exports = {

    a:a

}

ytest: function ()

{

console.log(‘ytest’);

}

module.exports={ytest:ytest}

VM5469:5 file: utils/chklogin.js

 unknown: Unexpected token (1:16)

 > 1 | ytest: function () 

    |                ^

  2 | { 

  3 |   console.log(‘ytest’);

  4 | }

回到顶部