CNode

我想问一下像下面这样引用模块中函数中的内嵌函数respondcommand行不行

问答
Ssunboy25发布于4 年前最后回复4 年前0 回复3946 浏览0 收藏

class IotDevice extends EventEmitter { constructor({serverAddress = "127.0.0.1:8883", productName, deviceName, secret, clientID, storePath} = {}) { super(); this.serverAddress = mqtts://${serverAddress} ...... }

handleCommand({commandName, requestID, encoding, payload, expiresAt, commandType = "cmd"}) { ....... var self = this var respondCommand = function (respData) { var topic = ${commandType}_resp/${self.productName}/${self.deviceName}/${commandName}/${requestID}/${new ObjectId().toHexString()} self.client.publish(topic, respData, { qos: 1 }) module.exports = IotDevice;

    •   在下面的另一个文件中引用上面模块中的handleCommand的内嵌函数respondCommand,这个方法对不对,如果可以请讲一下,怎样的情况下能这样引用?
      

var IotDevice = require("../sdk/iot_device") require('dotenv').config() var path = require('path');

var device = new IotDevice({ productName: process.env.PRODUCT_NAME, ....... }) device.on("command", function (command, data, respondCommand) { if (command == "ping") { console.log(get ping with: ${data.readUInt32BE(0)}) ......... respondCommand(buf) }

查看回复

回复 (0)

暂无回复,成为第一个参与讨论的人。
参与回复
登录后即可参与回复。登录