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>

猜你喜欢

转载自www.cnblogs.com/sske531549304/p/9386110.html