我有一个变量,其中有以乳胶格式编写的文本
let textVar ="$\frac{1}{2}$"
console.log(textVar)
"$rac{1}{2}"
console.log(String.raw`$\frac{1}{2}$`)
"$\frac{1}{2}$"
Run Code Online (Sandbox Code Playgroud)
当我这样做时,我会丢失转义字符(\+下一个字符)console.log(textVar)我了解文本中转义字符的功能,并且我需要添加双引号(\\)才能将它们保留在 中textVar,但我不能这样做
我发现String.raw`$\frac{1}{2}$`保留文本而不转义。
我可以以任何方式传递我的textVar信息吗?String.raw
但这不起作用String.raw`${textVar}`
尝试了解 go 上下文取消如何中止后续代码的执行
实验详情:
2secsum在单独的 go-routine 中调用另一个 func - 它为1sectest-run-1 和4sectest-run-2休眠3sec让 spin go 例程完成执行package main
import (
"context"
"fmt"
"log"
"time"
)
func main() {
c := context.Background()
childCtx, cancel := context.WithTimeout(c, 2*time.Second)
defer cancel()
ch := make(chan int, 1)
go sum(5, 6, ch)
var msg string
select {
case <-childCtx.Done():
msg = "return from ctx done channel"
case res := <-ch:
msg = …Run Code Online (Sandbox Code Playgroud)