Skip to content
Browse files

Could not map objects containing constructor

  • Loading branch information...
1 parent b586531 commit 00733c622a4c2ac98b4dbd4f01e2e5205b34292b @RoyJacobs RoyJacobs committed Apr 20, 2012
Showing with 12 additions and 1 deletion.
  1. +1 −1 knockout.mapping.js
  2. +11 −0 spec/mappingBehaviors.js
View
2 knockout.mapping.js
@@ -170,7 +170,7 @@
}
for (name in options) {
t = target[name]; o = options[name];
- if (special[name] && type(o) !== "array") {
+ if (name !== "constructor" && special[name] && type(o) !== "array") {
if (type(o) !== "string") {
throw new Error("ko.mapping.defaultOptions()." + name + " should be an array or string.");
}
View
11 spec/mappingBehaviors.js
@@ -1614,3 +1614,14 @@ test('ko.mapping.toJS should merge nested includes in an array', function() {
var result = ko.mapping.toJS(fromJS, { include: "c" });
equal(result.a[0].c[0], "c1");
});
+
+test('can map objects containing a constructor', function() {
+ var data = {
+ constructor: function() {},
+ a: 1
+ };
+
+ var mapped = ko.mapping.fromJS(data);
+ var unmapped = ko.mapping.toJS(mapped);
+ equal(unmapped.a, 1);
+});

0 comments on commit 00733c6

Please sign in to comment.
Something went wrong with that request. Please try again.