例如:
var person = {
firstName: "John",
lastName : "Doe",
language : "",
set lang(lang) {
this.language = lang.toUpperCase();
}
};
person.lang = "en";
console.log(person.language)
var person1 = {
firstName: "John",
lastName : "Doe",
language : function(a){return a.toUpperCase()}
};
console.log(person1.language('en'))
这看起来完全一样,并且方法模式编写得较少,所以我为什么要使用 setter?
qq_花开花谢_0
相关分类