diff --git a/mithril.js b/mithril.js index ed6d9b52..7db73997 100644 --- a/mithril.js +++ b/mithril.js @@ -313,10 +313,14 @@ new function(window) { //model m.prop = function(store) { - return function() { + var f = function() { if (arguments.length) store = arguments[0] return store } + f.toJSON = function() { + return store + } + return f } m.deferred = function() { diff --git a/tests/mithril-tests.js b/tests/mithril-tests.js index ad2aefe8..55923354 100644 --- a/tests/mithril-tests.js +++ b/tests/mithril-tests.js @@ -389,6 +389,14 @@ function testMithril(mock) { prop("foo") return prop() == "foo" }) + test(function() { + var prop = m.prop("test") + return JSON.stringify(prop) == "\"test\"" + }) + test(function() { + var obj = { prop: m.prop("test") } + return JSON.stringify(obj) == "{\"prop\":\"test\"}" + }) //m.request test(function() {