diff --git a/mithril.js b/mithril.js index bd55a22d..1b681b5c 100644 --- a/mithril.js +++ b/mithril.js @@ -319,10 +319,14 @@ Mithril = m = new function app(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 0619b62a..bb0700ee 100644 --- a/tests/mithril-tests.js +++ b/tests/mithril-tests.js @@ -419,6 +419,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() {