Javascript 中使用 const 与 freeze 的声明
原创javascript 常量
使用 const 我们仍然可以修改 javascript 对象的内容,但对该对象的引用将是不可变的。
const product = {name: "sugar", weight: "1 kg"}; product.name = "some new name"; console.log(product);
{ name: "some new name", weight: "1 kg" }
javascript 冻结
当我们不想修改对象的内容时,首选使用 freeze。
const product = {name: "sugar", weight: "1 kg"}; object.freeze(product); product.name = "some new name"; console.log(product);
{ name: "Sugar", weight: "1 kg" }
以上就是Javascript 中使用 const 与 freeze 的声明的详细内容,更多请关注IT视界其它相关文章!
上一篇:全面且用户友好的项目 READMEmd 模板 下一篇:恩卡什 v !!