【发布时间】:2014-12-28 02:50:09
【问题描述】:
function Name(first, last) {
this.first = first;
this.last = last;
this.fullName = first + " " + last
}
Name.prototype = {
get fullName() {
return this.first + " " + this.last;
},
set fullName(name) {
var names = name.split(" ");
this.first = names[0];
this.last = names[1];
}
};
var person = new Name("Foo", "Bar");
// person.fullName = "Foo Bar"
person.hasOwnProperty("fullName") // false
有没有办法返回属性?
【问题讨论】:
-
那么,您只是在问为什么
.hasOwnProperty()在您的情况下返回false?如果是这样,那么也许你真的应该问这个。