fix custom getter setter example
This commit is contained in:
parent
eed9c23b3e
commit
f803da2008
2 changed files with 8 additions and 2 deletions
|
|
@ -362,13 +362,19 @@ m.module(document, todo);
|
||||||
<pre><code class="lang-javascript">this.description = m.prop(data.description)</code></pre>
|
<pre><code class="lang-javascript">this.description = m.prop(data.description)</code></pre>
|
||||||
<p>becomes:</p>
|
<p>becomes:</p>
|
||||||
<pre><code class="lang-javascript">//private store
|
<pre><code class="lang-javascript">//private store
|
||||||
var description = data.description;
|
var description;
|
||||||
|
|
||||||
//public getter-setter
|
//public getter-setter
|
||||||
this.description = function(value) {
|
this.description = function(value) {
|
||||||
if (arguments.length > 0) description = value.toUpperCase();
|
if (arguments.length > 0) description = value.toUpperCase();
|
||||||
return description;
|
return description;
|
||||||
}</code></pre>
|
}
|
||||||
|
|
||||||
|
//make it serializable
|
||||||
|
this.description.toJSON = function() {return description}
|
||||||
|
|
||||||
|
//set the value
|
||||||
|
this.description(data.description)</code></pre>
|
||||||
<p>According to Mithril's philosophy, <code>list</code> and <code>description</code> are also considered model-level entities. This is a subtle but important point: model entities don't need to be full-blown custom classes.</p>
|
<p>According to Mithril's philosophy, <code>list</code> and <code>description</code> are also considered model-level entities. This is a subtle but important point: model entities don't need to be full-blown custom classes.</p>
|
||||||
<p>Native Javascript classes are quite appropriate for storing primitive and structured data. Since in this case they are indeed being used to store data - even if temporarily - they are model entities!</p>
|
<p>Native Javascript classes are quite appropriate for storing primitive and structured data. Since in this case they are indeed being used to store data - even if temporarily - they are model entities!</p>
|
||||||
<p>Be aware that by using the native Array class for a list, we're making an implicit statement that we are going to support all of the standard Array methods as part of our API.</p>
|
<p>Be aware that by using the native Array class for a list, we're making an implicit statement that we are going to support all of the standard Array methods as part of our API.</p>
|
||||||
|
|
|
||||||
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue