<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Uncategorized</title><link>http://timlabonne.com:80/uncategorized</link><description>Uncategorized</description><item><title>Alternative Approach to Extenders in Knockout.js</title><link>http://timlabonne.com:80/2013/02/alternative-approach-to-extenders-in-knockout-js/</link><description>&lt;pre class="csharpcode"&gt;ko.observable.fn.booleanValue = &lt;span class="kwrd"&gt;function&lt;/span&gt; () {
    &lt;span class="kwrd"&gt;var&lt;/span&gt; formattedValue = ko.computed({
        read: &lt;span class="kwrd"&gt;function&lt;/span&gt; () {
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;this&lt;/span&gt;() === &lt;span class="kwrd"&gt;true&lt;/span&gt;) &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="str"&gt;"True"&lt;/span&gt;;
            &lt;span class="kwrd"&gt;else&lt;/span&gt; &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;this&lt;/span&gt;() === &lt;span class="kwrd"&gt;false&lt;/span&gt;) &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="str"&gt;"False"&lt;/span&gt;;
        },
        write: &lt;span class="kwrd"&gt;function&lt;/span&gt; (newValue) {
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (newValue) {
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (newValue === &lt;span class="str"&gt;"False"&lt;/span&gt;) &lt;span class="kwrd"&gt;this&lt;/span&gt;(&lt;span class="kwrd"&gt;false&lt;/span&gt;);
                &lt;span class="kwrd"&gt;else&lt;/span&gt; &lt;span class="kwrd"&gt;if&lt;/span&gt; (newValue === &lt;span class="str"&gt;"True"&lt;/span&gt;) &lt;span class="kwrd"&gt;this&lt;/span&gt;(&lt;span class="kwrd"&gt;true&lt;/span&gt;);
            }
        }
    }, &lt;span class="kwrd"&gt;this&lt;/span&gt;);

    &lt;span class="kwrd"&gt;this&lt;/span&gt;.formattedValue = formattedValue;
    &lt;span class="kwrd"&gt;this&lt;/span&gt;.formattedValue(&lt;span class="kwrd"&gt;this&lt;/span&gt;());
    &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;;
};&lt;/pre&gt;
&lt;p&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
This code is an alternative to the previous post of how to do an extender for a Boolean value.&amp;nbsp; It works exactly like the extender, but instead attaches functionality to the .fn extension point of ko.observable.&amp;nbsp; To use this, do the following:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;this&lt;/span&gt;.wantsFriesWithThat = ko.observable(&lt;span class="kwrd"&gt;true&lt;/span&gt;).booleanValue();&lt;/pre&gt;This is a bit cleaner than using the extend() method.&amp;nbsp; If we wanted, we could send in parameters to further configure how this extension works, we could simply pass them to the booleanValue() function.&amp;nbsp; If you want to add another extender, you would simply chain another onto the call to booleanValue().&amp;nbsp; This is why the function returns this because the this in the function refers to the observable itself.
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;</description><pubDate>Thu, 28 Feb 2013 19:00:00 GMT</pubDate><guid isPermaLink="true">http://timlabonne.com:80/2013/02/alternative-approach-to-extenders-in-knockout-js/</guid></item><item><title>About This Blog</title><link>http://timlabonne.com:80/2013/02/about-this-blog/</link><description>&lt;p&gt;Hello World!&amp;nbsp; In this blog, I’m going to post snippets of code and things that I think are cool or useful to other people.&amp;nbsp; I’ve learned a lot from many other blogs out there and it is time for me to contribute something back.&lt;/p&gt; &lt;p&gt;I mostly develop for the .NET platform with C#, but I also do quite a bit of JavaScript development and general web stuff.&amp;nbsp; Hopefully you will find something useful here as I get around to posting things over time.&lt;/p&gt;</description><pubDate>Mon, 25 Feb 2013 15:28:00 GMT</pubDate><guid isPermaLink="true">http://timlabonne.com:80/2013/02/about-this-blog/</guid></item></channel></rss>