Javascript prototype undefined after eval deserialization
问题 Attempting to deserialize JSON data and update each object's prototype and inherit a common function. However, the following script throws error "people[0].getFullName is not a function". The prototype for deserialized objects appears to be undefined after assignment. <html> <head> <script> var json = '[ {"firstName": "John", "lastName": "Smith"}, {"firstName": "Nancy", "lastName": "Jones"} ]'; var people; eval('people = ' + json); function Person() { } Person.prototype.getFullName = function