给定以下代码:
function Person(firstName, lastName) {
this.FirstName = firstName;
this.LastName = lastName;
}
Person.prototype.showFullName = function() {
return this.FirstName + " " + this.LastName;
};
var person = new Person("xx", "xxxx");
var jsonString = JSON.stringify(person);
var thePerson = JSON.parse(jsonString);
我的目标是能够在 thePerson 上调用“showFullName”。虽然我知道 JS 并没有真正的对象,但它必须有某种方式能够说应该以某种方式对待某些东西,比如强制转换thePerson
为Person
.