使用closure来保护对象内部的属性不被外部修改
function Bird() {
let weight = 15;
this.getWeight = function() {
return weight;
};
}
let duck = new Bird();
duck.getWeight();
function Bird() {
let weight = 15;
this.getWeight = function() {
return weight;
};
}
let duck = new Bird();
duck.getWeight();