freeze

冻结: 即密封,又禁止修改所有属性值!
何时: 如果一个对象中保存了大量不变的属性值时
Object.freeze(obj);
其实是将所有属性的writable设置为false!

 

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script>
"use strict";

var config={
host:"localhost",
port:"27017",
db:"test",
uname:"root",
pwd:"root"
}
Object.freeze(config);
config.host="192.168.0.100";
</script>
</body>
</html>
posted @ 2018-07-29 17:52  BugLess000  阅读(220)  评论(0编辑  收藏  举报