之间的根本区别是什么
const json_response = pm.response.json()
Run Code Online (Sandbox Code Playgroud)
和
json_response = JSON.parse(responseBody)
Run Code Online (Sandbox Code Playgroud) 我正在使用Angular 6,我有一个简单的方法div,想div从模板内部设置它的背景色。通过正常颜色时,此方法效果很好。但这不适用于CSS变量。
这个例子有效
<div [style.background]="'red'">...</div>
Run Code Online (Sandbox Code Playgroud)
这个例子不起作用
<div [style.background]="'var(--some-css-var)'">...</div>
Run Code Online (Sandbox Code Playgroud) 我刚刚读到了 TypeScript 3.4 RC 中的新const断言功能,但我没有看到它与使用声明有何不同const。
我使用公告页面中的一个示例对此进行了测试,该示例显然演示了如何使用as const(const断言)防止文字类型被扩展(例如,"circle"to string)。
// Example from official announcement
function getShapes() {
let result = [
{ kind: "circle", radius: 100 },
{ kind: "square", sideLength: 50 },
] as const;
return result;
}
for (const shape of getShapes()) {
if (shape.kind === "circle") {
console.log("Circle radius", shape.radius);
} else {
console.log("Square side length", shape.sideLength);
}
}
// Output:
// Circle radius 100
// …Run Code Online (Sandbox Code Playgroud)