<!DOCTYPE html>
<html>
<head>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.18/angular.js"></script>
<script src="//cdn.jsdelivr.net/pouchdb/3.2.0/pouchdb.js"></script>
<script src="script.js"></script>
</head>
<body>
<h1>Run this and check the console!</h1>
</body>
</html>
function Movie(movieDTO) {
angular.extend(this, movieDTO);
}
Movie.prototype.getTitle = function() { return this.title; }; // WITHOUT THIS LINE THERE IS NO ERROR
var db = new PouchDB('groupByTest');
//db.destroy();
db.bulkDocs([
{"_id": "1", "title": "Rambo", "year": 2008, "genre": "Action"},
{"_id": "2", "title": "Forrest Gump", "year": 1994, "genre": "Drama"}
]).then(function () {
db.get("1", function(err, movieDTO) {
console.log("GET..............: "+JSON.stringify(movieDTO));
var movie = new Movie(movieDTO);
console.log("AFTER CONSTRUCTOR: "+JSON.stringify(movie));
movie.year++; // just so there is a change
// movie = angular.extend({}, movie); // UNCOMMENT THIS LINE TO SEE THE WORKAROUND I USED
db.put(movie, function(errorOnPut, putMsg) {
console.log("errorOnPut: "+JSON.stringify(errorOnPut));
console.log("putMsg....: "+JSON.stringify(putMsg));
});
});
});