【问题标题】:Syntax Error - unexpected identifier (XMPP with Node)语法错误 - 意外标识符(带节点的 XMPP)
【发布时间】:2017-05-21 18:20:50
【问题描述】:

语法错误 - 带有节点的意外标识符 XMPP

我是 Node 和 XMPP 的新手,使用 ltx 阅读聊天节时出现错误,错误是:。

const logEntry = 'Received message from ' ${from} ' with ^ SyntaxError: Unexpected identifier

at createScript (vm.js:56:10) at Object.runInThisContext (vm.js:97:10) at Module._compile (module.js:542:28) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) at Module.runMain (module.js:604:10) at run (bootstrap_node.js:390:7) at startup (bootstrap_node.js:150:9)

文件名为:index.js

代码如下:

    const Client = require('node-xmpp-client')
, ltx = Client.ltx
const options = {
jid: 'bot@localhost',
password: 'tellnoone'
}
const client = new Client(options)
client.on('online', (connectionDetails) => {
console.log('We are connected!')
console.log(connectionDetails)
sendPresence()
})
const sendPresence = () => {
var stanza = new ltx.Element('presence')
console.log('Sending presence: ' + stanza.toString())
client.send(stanza)
}
client.on('stanza', (stanza) => {
if (false === stanza.is('message')) return /* Not a <message/> stanza */
const messageContent = stanza.getChildText('body')
if (!messageContent) return /* Not a chat message */
const from = stanza.attr('from')
const logEntry = 'Received message from ' ${from} ' with
content:\n${messageContent}'
console.log(logEntry)
})

【问题讨论】:

    标签: javascript node.js ecmascript-6 xmpp


    【解决方案1】:

    换行试试

    const logEntry = 'Received message from ' ${from} ' with content:\n${messageContent}'

    const logEntry = `Received message from ${from} with content:\n ${messageContent}`

    模板字符串使用反引号而不是引号。

    【讨论】:

      猜你喜欢
      • 2014-07-25
      • 2015-10-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-05
      相关资源
      最近更新 更多