'use strict'; const a = 'test'; // node.js 文件操作对象 module.exports = { test() { // this 就是 app 对象,在其中可以调用 app 上的其他方法,或访问属性 }, get testA() { return this[a]; }, // 生成length位随机数 randomCode(length) { const chars = [ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' ]; let result = ''; for (let i = 0; i < length; i++) { const index = Math.ceil(Math.random() * 9); result += chars[index]; } return result; }, isString(obj) { return typeof obj === 'string'; }, isObject(obj) { return Object.prototype.toString.call(obj) === '[object Object]'; }, isUndefined(obj) { return Object.prototype.toString.call(obj) === 'undefined'; }, isArray(arr) { return Object.prototype.toString.call(arr) === '[object Array]'; }, };