这些奇怪的符号在js中意味着什么?

时间:2016-07-02 05:08:40

标签: javascript

它来自if语句,他们使用es6但从未见过'/#'。任何人都在意解释。 (注意从堆栈流中删除反引号)

以下是代码片段: https://codedump.io/share/LPW9jWNDJZwl/1/weird-javascript 如果它可以提供帮助,那么这是package.json:https://codedump.io/share/HlvwlcmeiPW9/1/packagejson

    // Flash around where you have just spawned
    if (`/#${this.socket.id}` === player.id &&
            player.moveCounter <= ClientConfig.TURNS_TO_FLASH_AFTER_SPAWN &&
            player.moveCounter % 2 === 0) {
        this.canvasView.drawSquareAround(player.segments[0], ClientConfig.SPAWN_FLASH_COLOR);
    }

    if (player.base64Image) {
        this.canvasView.drawImages(player.segments, player.base64Image);
    } else {
        this.canvasView.drawSquares(player.segments, player.color);
    }
}

1 个答案:

答案 0 :(得分:-1)

反引号是template literals。在这种情况下,

假设`/#${this.socket.id}`的值为1,

"/#1"成为字符串this.socket.id