我想问一下像下面这样引用模块中函数中的内嵌函数respondcommand行不行
发布于 3 年前 作者 sunboy25 3178 次浏览 来自 问答

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) }

回到顶部