SteveSanderson/knockout.mapping — Issue #37: Suspicious behaviour of update callback
Author: Anber
Created: 2011-10-25 22:02:51+00:00
State: open

var someObjectModel = function(data) {
ko.mapping.fromJS(data, {}, this);
}

var mapping = {
'prop': {
update: function(options) {
var res = options.data ? new someObjectModel(options.data) : null;
return ko.observable(res);
}
}
}

var obj_1 = {
prop: null
};

var obj_2 = {
prop: {}
};

var viewModel_1 = ko.mapping.fromJS(obj_1, mapping);
var viewModel_2 = ko.mapping.fromJS(obj_2, mapping);

console.log(typeof viewModel_1.prop, typeof viewModel_2.prop); // function function — Ok
console.log(typeof viewModel_1.prop(), typeof viewModel_2.prop()); // function object — Bug?

But «typeof viewModel_1.prop()» returns «object» if replace «update» on «create».