<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Caffeinated Simpleton</title>
	
	<link>http://justin.harmonize.fm</link>
	<description>A cup of coffee and a soapbox is like a bottle of Jack and a gun.</description>
	<lastBuildDate>Mon, 15 Feb 2010 08:06:40 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/CaffeinatedSimpleton" /><feedburner:info uri="caffeinatedsimpleton" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Cobra is Ready to Release</title>
		<link>http://feedproxy.google.com/~r/CaffeinatedSimpleton/~3/mi8_mMd_m8o/</link>
		<comments>http://justin.harmonize.fm/index.php/2010/02/cobra-is-ready-to-release/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 08:06:40 +0000</pubDate>
		<dc:creator>justin</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Cobra]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://justin.harmonize.fm/?p=346</guid>
		<description><![CDATA[I did a little work on Cobra today and pushed the code around a little bit. Things that changed:

Reorganized into a single closure. This helps keep internal details internal.
Minimize with Closure Compiler
JSLint now passes

I definitely recommend the JSLint VIM plugin if you&#8217;re a vimmer.


Works in node.js (and most likely any server-side JavaScript implementation)
Works in Internet [...]]]></description>
			<content:encoded><![CDATA[<p>I did a little work on Cobra today and pushed the code around a little bit. Things that changed:</p>
<ul>
<li>Reorganized into a single closure. This helps keep internal details internal.</li>
<li>Minimize with <a href="http://code.google.com/closure/compiler/" target="_blank">Closure Compiler</a></li>
<li><a href="http://www.jslint.com/" target="_blank">JSLint</a> now passes
<ul>
<li>I definitely recommend the <a href="http://github.com/hallettj/jslint.vim" target="_blank">JSLint VIM plugin</a> if you&#8217;re a vimmer.</li>
</ul>
</li>
<li>Works in <a href="http://nodejs.org/" target="_blank">node.js</a> (and most likely any server-side JavaScript implementation)</li>
<li>Works in Internet Explorer.
<ul>
<li>I had never really tested this, but after fixing the things that JSLint found, the tests just passed.</li>
<li>Still need to test in IE 6. I don&#8217;t have a machine with IE 6 unfortunately.</li>
</ul>
</li>
<li>Added to documentation to clarify a few things.</li>
</ul>
<p>At this point, I think the library&#8217;s safe for others to use. I tagged a 0.5 version, and I&#8217;ll be calling it 1.0 after it gets into a few more projects. Feel free to try it out!</p>
<p>You can find <a href="http://github.com/jmtulloss/cobra">Cobra on github</a>, or you can <a href="http://github.com/jmtulloss/cobra/zipball/0.5">download version 0.5 now</a> (<a href="http://github.com/jmtulloss/cobra/tarball/0.5">tgz</a>).</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/CaffeinatedSimpleton?a=mi8_mMd_m8o:Y7qgOP-0iwA:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/CaffeinatedSimpleton?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/CaffeinatedSimpleton?a=mi8_mMd_m8o:Y7qgOP-0iwA:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/CaffeinatedSimpleton?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/CaffeinatedSimpleton?a=mi8_mMd_m8o:Y7qgOP-0iwA:3Id5NbicZDU"><img src="http://feeds.feedburner.com/~ff/CaffeinatedSimpleton?i=mi8_mMd_m8o:Y7qgOP-0iwA:3Id5NbicZDU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/CaffeinatedSimpleton/~4/mi8_mMd_m8o" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://justin.harmonize.fm/index.php/2010/02/cobra-is-ready-to-release/feed/</wfw:commentRss>
		<slash:comments>-1</slash:comments>
		<feedburner:origLink>http://justin.harmonize.fm/index.php/2010/02/cobra-is-ready-to-release/</feedburner:origLink></item>
		<item>
		<title>Sports Bring Peace</title>
		<link>http://feedproxy.google.com/~r/CaffeinatedSimpleton/~3/dosPV_tDdVg/</link>
		<comments>http://justin.harmonize.fm/index.php/2010/02/sports-bring-peace/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 04:35:53 +0000</pubDate>
		<dc:creator>justin</dc:creator>
				<category><![CDATA[What I'm thinking]]></category>
		<category><![CDATA[Christopher Hitchens]]></category>
		<category><![CDATA[instincts]]></category>
		<category><![CDATA[sports]]></category>
		<category><![CDATA[World Peace]]></category>

		<guid isPermaLink="false">http://justin.harmonize.fm/?p=330</guid>
		<description><![CDATA[In a typically whiny and smug editorial in this week&#8217;s Newsweek, Christopher Hitchens rants that sports are the cause of much needless political strife and that celebrating the athletes that make these spectacles possible degrades us all. He equates sports fans to children or some sort of uneducated, redneck mob that follows manufactured allegiances to murder, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://justin.harmonize.fm/wp-content/uploads/2010/02/torch-mob.jpg"><img class="alignright size-full wp-image-333" title="Your typical sports fans." src="http://justin.harmonize.fm/wp-content/uploads/2010/02/torch-mob.jpg" alt="" width="350" height="298" /></a>In a typically whiny and smug <a href="http://www.newsweek.com/id/233007" target="_blank">editorial in this week&#8217;s Newsweek</a>, <a id="aptureLink_QXckUmtqJm" href="http://en.wikipedia.org/wiki/Christopher%20Hitchens">Christopher Hitchens</a> rants that sports are the cause of much needless political strife and that celebrating the athletes that make these spectacles possible degrades us all. He equates sports fans to children or some sort of uneducated, redneck mob that follows manufactured allegiances to murder, war, and ignorance. This all is, of course, ridiculous, not to mention offensive to the thoughtful, well-educated individuals who understand and care about sports.</p>
<p>Hitchens&#8217; main line of reasoning stems from a few anecdotes that he brings together to create an overly pessimistic picture of sports creating international tension. This kind of journalism is sickening, but typical, as it poses a number of loosely similar stories as facts that reach a hard conclusion without even suggesting alternative sides of the story. It is nothing more than tabloid-esque entertainment, but nevertheless I am compelled to present a different vision of sports in America and the world as a whole.</p>
<p><a href="http://justin.harmonize.fm/wp-content/uploads/2010/02/chimpgun.jpg"><img class="alignleft size-full wp-image-340" title="Early humans before sports." src="http://justin.harmonize.fm/wp-content/uploads/2010/02/chimpgun.jpg" alt="" width="300" height="210" /></a>Since humanity has formed into nations, cultures, religions, and a number of other ways of organizing themselves, there has been a basic problem. In a world in which it is more likely that you do not know somebody than you do know them, how do we interact, probe each others strengths and weaknesses, find common ground, and establish community with people we have no interaction with? Discussing economics, religion, or politics is more likely to breed conflict than mutual understanding. You cannot compete with somebody who is willing to die rather than give ground on a subject. Competitions, as a natural tribal instinct, had to evolve into a different form. I am always going to want to best by sister at any give topic. My family will want to best the neighbors. The town will want to best the next town over. The state will want to best the next state. If we ever find alien life forms, Earth will want to show their superiority. There should be a way to fulfill this natural need to compete without killing everyone. Sports is that way.</p>
<p>This point seems to play right into sports opponents hands. They would say that sports are still a reflection of animal instincts that we can grow out of, that&#8217;s it&#8217;s somehow base. I strongly disagree. Sports are the civilized competition, the way we teach and learn how to resolve differences without resorting to violence. Sports are islands of peace in a world riddled with genuine conflict. They provide tribal community without pushing us towards its violence.</p>
<p>The key to sports peaceful nature is that they, in and of themselves, don&#8217;t matter. They are not a higher cause. When they become representative of a higher cause, trouble ensues, but when they are kept to the level of competition for competition&#8217;s sake, then there is no reason for animosity to endure, or to break into violence. This allows for community on both sides of the competition, which allows us to ignore the potentially violent differences individuals have in their everyday lives.</p>
<p><a href="http://justin.harmonize.fm/wp-content/uploads/2010/02/uiuc.png"><img class="alignright size-full wp-image-338" title="University of Illinois at Urbana-Champaign" src="http://justin.harmonize.fm/wp-content/uploads/2010/02/uiuc.png" alt="" width="115" height="149" /></a>College is a great example. While I probably do not have an causes that I will violently enforce, many people that are thrown together on the same university do. Israelis and Palestinians sit next to each other in lecture. Blacks and whites, Armenians and Turks, and hundreds of other traditionally irreconcilable cultures, religions, and nationalities interact with each other every day. How is it possible to create a cohesive community out of such a widely varied population? Sports. A few chosen athletes are tasked with representing this created community in a way that we can all join together and push past our differences. This community now has a face, something to fight for, but not in a violent way. We can peacefully come together around this one cause.</p>
<p><a href="http://justin.harmonize.fm/wp-content/uploads/2010/02/bovswoody1.jpg"><img class="alignleft size-full wp-image-336" title="Bo Vs Woody" src="http://justin.harmonize.fm/wp-content/uploads/2010/02/bovswoody1.jpg" alt="" width="351" height="212" /></a>The same concept applies to localities, states, and nations. If I meet an older, latino, blue-collar worker on a bus or in a bar, I have nothing obviously in common with this man. Throw on an Ohio State sweatshirt, and suddenly we can talk for hours. What&#8217;s more, throw a Michigan sweatshirt on the man, and we can still have a civil conversation. We are rivals, but not the kind that you can&#8217;t have a beer with. In fact, I am offered an understanding of how the man thinks that I would not normally have. I know he hates me the same way I hate him, and we can bond over that. The same principle applies to a San Francisco shirt in San Francisco, or a Die Mannschaft jersey in Germany.</p>
<p>Sports at their core are about peaceful competition. So how is there so much violence? The violence is caused by the same things that cause violence outside of sports, sports are sometimes just mixed up into the equation. Violence is frequently caused by money, religion, cultural differences, and a whole slew of other things. When the sports teams representing two sides that are already entangled in a conflict meet, one of two things can happen. The competition can remind everybody of their shared interests, or they can serve as a catalyst to a violent conflict. While I believe that the majority of the data suggests the former, I have no proof of this. The important point is, the violence is not caused by the sport itself. It&#8217;s caused by the things that always drive us apart. Sports themselves, when played out as they are intended, can only bring peace.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/CaffeinatedSimpleton?a=dosPV_tDdVg:tEsK31b5DYA:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/CaffeinatedSimpleton?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/CaffeinatedSimpleton?a=dosPV_tDdVg:tEsK31b5DYA:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/CaffeinatedSimpleton?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/CaffeinatedSimpleton?a=dosPV_tDdVg:tEsK31b5DYA:3Id5NbicZDU"><img src="http://feeds.feedburner.com/~ff/CaffeinatedSimpleton?i=dosPV_tDdVg:tEsK31b5DYA:3Id5NbicZDU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/CaffeinatedSimpleton/~4/dosPV_tDdVg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://justin.harmonize.fm/index.php/2010/02/sports-bring-peace/feed/</wfw:commentRss>
		<slash:comments>-1</slash:comments>
		<feedburner:origLink>http://justin.harmonize.fm/index.php/2010/02/sports-bring-peace/</feedburner:origLink></item>
		<item>
		<title>Healthcare as a Moral Imperative</title>
		<link>http://feedproxy.google.com/~r/CaffeinatedSimpleton/~3/ENakcA_EieI/</link>
		<comments>http://justin.harmonize.fm/index.php/2009/12/healthcare-as-a-moral-imperative/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 08:18:36 +0000</pubDate>
		<dc:creator>justin</dc:creator>
				<category><![CDATA[Politics]]></category>
		<category><![CDATA[healthcare]]></category>
		<category><![CDATA[morality]]></category>
		<category><![CDATA[rights]]></category>

		<guid isPermaLink="false">http://justin.harmonize.fm/?p=296</guid>
		<description><![CDATA[In any political debate, there is rhetoric used by both sides to imply how obviously correct their position is. The current healthcare debate is no different, with &#8220;healthcare is a right&#8221; being a favorite phrase of those on the left. Those that use the phrase take it to mean that every person deserves some form [...]]]></description>
			<content:encoded><![CDATA[<p>In any political debate, there is rhetoric used by both sides to imply how obviously correct their position is. The current healthcare debate is no different, with &#8220;healthcare is a right&#8221; being a favorite phrase of those on the left. Those that use the phrase take it to mean that every person deserves some form of healthcare. However, this is not what a &#8220;right&#8221; is. Rights are those properties of a human being that are granted to us because, and only because, we are human. They are granted a priori, and cannot be denied us except through force and submission. Healthcare does not fall into this category. Healthcare is something that is consumed, and is therefore granted by those that have it to those that do not (usually in exchange for some other good, mostly cold, hard cash these days). Nothing that falls in this category can be a basic human right, as the providers themselves have the right to determine who they provide to.</p>
<p>Whether or not healthcare is a right, however, is not the debate. Rather, it&#8217;s a tactic used by one side to make an argument in a sentence instead of in a carefully constructed thesis. What those in favor of healthcare reform are trying to push for is the idea that we, as a society, have some moral imperative to force the provider&#8217;s hand and provide some level of healthcare to all, whether providing such care is beneficial to the provider or not. This is an argument for a restriction of rights, which, paradoxically, is something goverments have been granted the right to do by their citizens.</p>
<p>The question then is how much we are morally obligated to restrict the freedoms of healthcare providers in order bring the general health to some acceptable level. This is a very difficult question, made more difficult by the fact that the value of healthcare changes with time and economic prosperity. This is a terrific example of imperfect duty, a duty which is never complete but which we are morally bound to strive to make progress on. We have made great progress too. Healthcare as it exists today is better than at any previous point in history and available to more people. It does seem to be the case, however, that society feels that too many of its members are in a situation where they do not have access to the kinds of care that should be available to all. This probably doesn&#8217;t include very expensive experimental treatments, but does include expensive but common procedures and treatments like those used to fight cancer, heart disease, and other widespread diseases.</p>
<p>The current legislation is too large for me to really know what&#8217;s in it, but the goals are fairly clear. The bill is meant to require health insurance for almost all Americans, require coverage for those with preexisting conditions, make selecting insurance options more transparent, facilitate keeping your insurance between jobs, and providing some form of publicly funded insurance. These components really try to kill two (or perhaps 3 or 4) birds with one stone. In addition to the much touted coverage for those that are currently without, a large portion of the bill is designed to make health coverage more manageable by individuals. That sounds great to those of us that have healthcare that we really don&#8217;t even know how to use, but doesn&#8217;t really take steps towards fulfilling our society&#8217;s imperfect duty. Perhaps that&#8217;s why we don&#8217;t hear a whole lot about that part of the bill.</p>
<p>Whatever ends up in the final bill, it seems to me that it will not fulfill any of its goals. The less talked about goal, that of making health insurance more manageable by its own customers, is not something governments are particularly good at. It&#8217;s difficult to regulate complexity. The best way to achieve this goal is competition. This would require insurance companies to market straight to consumers instead of their employers. You can be sure that insurance companies will become more transparent in a hurry when they have to convince you that they are actually better than the next guy rather than your company&#8217;s HR department. Auto insurance, for instance, is substantially simpler than its healthcare counterparts.</p>
<p>Where government is probably not the best answer for reducing the complexity of the healthcare system, government has become the preferred vessel for carrying out society&#8217;s obligations to itself. In the current debate, this has translated to &#8220;we must provide insurance to the uninsured&#8221;. This seems noble enough, except that the insurance model itself is deeply flawed. Those of us that already have insurance can see this quite obviously. We do not know the cost of healthcare, nor do we care. Co-pays are minimal, so we take what healthcare we need and bill the insurance company. For those of us with insurance, healthcare is near free and limitless. It stands to reason, then, that by providing insurance to those without, they will also have unlimited, near free healthcare.</p>
<p>The question then becomes, is unlimited, free healthcare the fulfillment of our moral obligation? I believe that it is not. Society should not be asked to cover the costs of keeping the elderly around longer than is prudent, nor should we be asked to bear the burdens of an individual&#8217;s poor decisions. Society should provide the level of healthcare that most of us enjoy to as many as possible, but we should not give a blank check.</p>
<p>Many are disgusted by the idea of trying to figure out who should get what healthcare. It does not seem ethical to have &#8220;death panels&#8221; or enforce that your bypass will only be covered if you didn&#8217;t eat bacon for a year. Should we provide orthodontics, which seem like a luxury until you look at the importance of good teeth in the white collar world? Again, this is one of those things that government does a poor job of regulating, and again, these decisions should be left up to the individual. How we do this is something that the current legislation doesn&#8217;t touch, and I believe is absolutely necessary for true healthcare reform.</p>
<p>Structuring the system to provide individual responsibility while still providing healthcare to those that cannot afford it seems fairly straightforward to me. Offering insurance policies with very high deductibles and supplementing them with health savings accounts ensures that an individual can determine their own regular healthcare needs while still being protected from unexpected disasters. Both the policies and the savings accounts can be subsidized or provided by the government, with the expectation that the individual contributes what they can. This simple combination seems to be the best bet for minimizing government&#8217;s interference in an individuals healthcare while still providing them with the level of care the rest of society enjoys.</p>
<p>There is a serious caveat to this seemingly simple solution. That caveat is that all health services, not just disasters, are obscenely expensive and getting pricier. I believe this is a direct result of the structure of the current private insurance industry. Since nobody except for the insurance companies care what the cost of health services is, and the insurance companies are buying in bulk, there is a strong incentive for the hospitals to reduce the costs of those services that the insurance companies will object to while increasing the costs of those services that are cheap by comparison. Added to the burden is the cost of patients that are unable to pay. The effect of the hospitals &#8220;making up&#8221; money by increasing costs of routine services is that all healthcare services are more expensive, without any incentive for them being made cheaper.</p>
<p>The current proposal for dealing with the cost problem is for the government to provide a public option to &#8220;compete&#8221; with the private insurers. I don&#8217;t understand this reasoning in the least, but it hasn&#8217;t been well explained by its proponents, so I could be missing something. Regardless of its ability to provide competition in an already highly competitive market place, the public option is fundamentally flawed since its structured like a traditional insurance company. It will have similar incentives, none of which will encourage lowering the costs of routine healthcare.</p>
<p>A better method for controlling costs is to make sure individuals are aware of them. If people are asked to pay for routine health services, they will pay much closer attention to the costs of these services. The best way to get individuals to pay for routine services is the same method by which we should cover those without insurance: through health savings accounts combined with high deductible insurance policies. </p>
<p>If those that can afford insurance are on a plan similarly structured to those that can&#8217;t, then we have a system in which the market can drive down the costs of things that should be cheap while insuring that those things that are not affordable are available to those that really need them. This seems to be the easiest and least error prone method of reforming healthcare.</p>
<p>There are a number of ways to fulfill the nebulous goal of providing healthcare to everybody in America. One way is to buy into the current system and ask society to pay for it. Another is to restructure the system in a way that benefits everyone and only then ask society to provide those minimal services it has deemed morally necessary to provide to its citizens. The latter seems like the more prudent, more moral, and simpler way to make this generation&#8217;s contribution to that imperfect duty that is healthcare.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/CaffeinatedSimpleton?a=ENakcA_EieI:YVpEa352K74:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/CaffeinatedSimpleton?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/CaffeinatedSimpleton?a=ENakcA_EieI:YVpEa352K74:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/CaffeinatedSimpleton?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/CaffeinatedSimpleton?a=ENakcA_EieI:YVpEa352K74:3Id5NbicZDU"><img src="http://feeds.feedburner.com/~ff/CaffeinatedSimpleton?i=ENakcA_EieI:YVpEa352K74:3Id5NbicZDU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/CaffeinatedSimpleton/~4/ENakcA_EieI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://justin.harmonize.fm/index.php/2009/12/healthcare-as-a-moral-imperative/feed/</wfw:commentRss>
		<slash:comments>-1</slash:comments>
		<feedburner:origLink>http://justin.harmonize.fm/index.php/2009/12/healthcare-as-a-moral-imperative/</feedburner:origLink></item>
		<item>
		<title>An Introduction to JavaScript’s “this”</title>
		<link>http://feedproxy.google.com/~r/CaffeinatedSimpleton/~3/9-t1xlSNHp0/</link>
		<comments>http://justin.harmonize.fm/index.php/2009/09/an-introduction-to-javascripts-this/#comments</comments>
		<pubDate>Sun, 27 Sep 2009 01:27:43 +0000</pubDate>
		<dc:creator>justin</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[this]]></category>

		<guid isPermaLink="false">http://justin.harmonize.fm/?p=298</guid>
		<description><![CDATA[JavaScript is an amazing little language, but it&#8217;s got some quirks that turn a lot of people off. One of those quirks is this, and how it&#8217;s not necessarily what you expect it to be. this isn&#8217;t that complicated, but there are very few explanations of how it works on the internet. I find myself [...]]]></description>
			<content:encoded><![CDATA[<p>JavaScript is an amazing little language, but it&#8217;s got some quirks that turn a lot of people off. One of those quirks is <code>this</code>, and how it&#8217;s not necessarily what you expect it to be. <code>this</code> isn&#8217;t that complicated, but there are very few explanations of how it works on the internet. I find myself constantly re-explaining the concept to those who are new to JavaScript development. This article is an attempt to explain how <code>this</code> works and how to use it properly.</p>
<h2>What is <code>this</code>?!</h2>
<p><code>this</code> is the current object. People that are used to object oriented languages use objects constantly, and <code>this</code> is how you access your object in JavaScript. This differs from Java and C++. This is best demonstrated by example, so let&#8217;s take a look.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp cpp" style="font-family:monospace;"><span style="color: #0000ff;">class</span> HotDog <span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
     string getCondiments<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>;
<span style="color: #0000ff;">private</span><span style="color: #008080;">:</span>
     string condiments;
<span style="color: #008000;">&#125;</span>
&nbsp;
string HotDog<span style="color: #008080;">::</span><span style="color: #007788;">getCondiments</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">return</span> condiments; <span style="color: #666666;">// The compiler knows to find &quot;condiments&quot; in the current HotDog instance</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>Ruby and Python don&#8217;t work this way. Instead, you must say &#8220;look for this variable in the current instance&#8221;</p>

<div class="wp_syntax"><div class="code"><pre class="python python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">class</span> HotDog:
    condiments
    <span style="color: #ff7700;font-weight:bold;">def</span> getCondiments<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
         <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">self</span>.<span style="color: black;">condiments</span> <span style="color: #808080; font-style: italic;"># &quot;self&quot; is a reference to the current instance of HotDog.</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby ruby" style="font-family:monospace;">  <span style="color:#9966CC; font-weight:bold;">class</span> HotDog
         <span style="color:#0066ff; font-weight:bold;">@condiments</span>
         <span style="color:#9966CC; font-weight:bold;">def</span> getCondiments
              <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#0066ff; font-weight:bold;">@condiments</span> <span style="color:#008000; font-style:italic;"># @condiments is an instance variable of an instance of HotDog</span>
         <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>JavaScript has more in common with Ruby and Python than with Java and C++. The same thing in JavaScript is:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> HotDog<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">condiments</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;mustard, ketchup&quot;</span>;
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">getCondiments</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">condiments</span>; <span style="color: #006600; font-style: italic;">//this is expected to be a reference to the current instance</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>That&#8217;s what <code>this</code> is expected to be, anyway. It&#8217;s expected to be a reference to the current instance of whatever object it&#8217;s defined within.</p>
<h3><code>this</code> Gets Tricky</h3>
<p>However, let&#8217;s say we wanted to find out what condiments were on our hotdog in 30 seconds. Assuming the HotDog class from above, that code might look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> myHotDog <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> HotDog<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #006600; font-style: italic;">// Call the getCondiments function in 3 seconds</span>
setTimeout<span style="color: #009900;">&#40;</span>myHotDog.<span style="color: #660066;">getCondiments</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">3000</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>Many JavaScript beginners are surprised to learn that this code won&#8217;t work. It&#8217;ll give an error saying that <code>this</code> doesn&#8217;t have a member called <code>condiments</code>, even though it clearly does. What happened?!</p>
<p>As it turns out, <code>this</code> in the <code>getCondiments</code> function is set to the global object, <code>window</code>. This is because there is no binding of functions to instances in JavaScript. Whenever the instance isn&#8217;t explicitly stated, then <code>this</code> becomes <code>window</code> (at least in the browser). Writing this as <code>myHotDog.getCondiments()</code> indicates that you want <code>this</code> to be <code>myHotDog</code>, so it works correctly. The <code>setTimeout</code> function, however, just has a reference to that function. When it calls it, it&#8217;s not aware of <code>myHotDog</code>, so JavaScript sets <code>this</code> to <code>window</code></p>
<h2>&#8220;Fixing&#8221; <code>this</code></h2>
<p>There are several ways of forcing this to be what you want, and many of them touch on some of the more interesting features available in JavaScript. The first is <code>apply</code>. <code>apply</code> is a member of every function. It says &#8220;call this function with this object as this and these arguments. An example might help.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// These two are equivalent</span>
myHotDog.<span style="color: #660066;">getCondiments</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
myHotDog.<span style="color: #660066;">getCondiments</span>.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span>myHotDog<span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #006600; font-style: italic;">// You could also do this</span>
<span style="color: #003366; font-weight: bold;">var</span> yourHotDog <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> HotDog<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
myHotDog.<span style="color: #660066;">getCondiments</span>.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span>yourHotDog<span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #006600; font-style: italic;">// The above line does the same thing as:</span>
yourHotDog.<span style="color: #660066;">getCondiments</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #006600; font-style: italic;">// The above two calls will return the condiments off of your hot dog, not mine.</span></pre></div></div>

<p>That doesn&#8217;t solve our <code>setTimeout</code> problem, however. <code>apply</code> actually calls the function, and we just want a reference to the function that uses the correct <code>this</code>. Luckily this is easily done, but let&#8217;s talk about some background first.</p>
<h3>Lexical Scoping</h3>
<p>In many languages (all the good ones, if you ask me), <a href="http://en.wikipedia.org/wiki/Scope_%28programming%29#Static_scoping_.28also_known_as_lexical_scoping.29">lexical scoping</a> is supported. Lexical scoping basically allows you to access local variables in a parent function. If a function is defined within another function, it can access its own local variables as well as those of the function it was defined within. Time for another example.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> drinkBeer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> beer <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;Big Daddy IPA&quot;</span>;
    <span style="color: #003366; font-weight: bold;">function</span> pour<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #003366; font-weight: bold;">var</span> glass <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;Pint Glass&quot;</span>;
         <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">&quot;Poured &quot;</span> <span style="color: #339933;">+</span> beer <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; into a &quot;</span> <span style="color: #339933;">+</span> glass;
   <span style="color: #009900;">&#125;</span>
   <span style="color: #003366; font-weight: bold;">function</span> drink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         beer <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span>;
         <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">&quot;Beer is all gone&quot;</span>;
   <span style="color: #009900;">&#125;</span>
   pour<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
   drink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span>
drinkBeer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>This works just fine. <code>drinkBeer</code> cannot access <code>glass</code>, but <code>pour</code> and <code>drink</code> can access <code>beer</code>.</p>
<p>Lexical scoping is extremely powerful. If this small example doesn&#8217;t explain it, I encourage you to look around other examples on the internet until it&#8217;s more clear. While writing JavaScript, look out for ways this can make your life easier. Once you&#8217;re looking, they&#8217;re all over the place.</p>
<h3>Solving our <code>setTimeout</code> Problem</h3>
<p>With lexical scoping, we can easily solve our <code>setTimeout</code> problem.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> myHotDog <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> HotDog<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
setTimeout<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    myHotDog.<span style="color: #660066;">getCondiments</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">3000</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>See what we did there? We created a new function that we passed to <code>setTimeout</code>. Our new function can access <code>myHotDog</code>, so it just applies it to the <code>getCondiments</code> function. Pretty slick.</p>
<h3>Defending against <code>this</code> abuse</h3>
<p>As somebody writing the <code>HotDog</code> class, it might be upsetting to you that people constantly need to keep <code>this</code> in mind when accessing your class. It would be nicer if there was a way to make your class work all the time. Fortunately, there is!</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> HotDog<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> my <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>; <span style="color: #006600; font-style: italic;">// my references the current this, which is correct.</span>
    my.<span style="color: #660066;">condiments</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;mustard, ketchup&quot;</span>;
    my.<span style="color: #660066;">getCondiments</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #000066; font-weight: bold;">return</span> my.<span style="color: #660066;">condiments</span>; <span style="color: #006600; font-style: italic;">//my is guaranteed to be a reference to the original &quot;this&quot;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><code>HotDog</code> is a constructor. You instantiate a new instance of <code>HotDog</code> by writing &#8220;<code>new HotDog()</code>&#8220;. In constructors, <code>this</code> is always your instance. So we created a new variable, my, that references the <code>HotDog</code> instance. This allows you to always refer to the <code>HotDog</code> instance, no matter how the <code>getCondiments</code> function is called.</p>
<h3>Bind</h3>
<p>Another method of &#8220;fixing&#8221; <code>this</code> is adding a <code>bind</code> attribute to every function. This allows you to pass in an object that will be your <code>this</code>. Many JavaScript libraries, such as <a href="http://www.prototypejs.org/">Prototype</a>, do this.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> boundFunction <span style="color: #339933;">=</span> myHotDog.<span style="color: #660066;">getCondiments</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span>myHotDog<span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>Now <code>boundFunction</code> will always call <code>getCondiments</code> with <code>this</code> set to <code>myHotDog</code>. If you&#8217;ve been paying attention, it should be fairly obvious how bind is written.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> bind<span style="color: #009900;">&#40;</span>thisObject<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> my <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>; <span style="color: #006600; font-style: italic;">// this is the function here</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        my.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span>thisObject<span style="color: #009900;">&#41;</span>;
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>Cobra</h3>
<p>My own class library, <a href="http://justin.harmonize.fm/index.php/2009/01/cobra-a-little-javascript-class-library/">cobra</a>, solves the <code>this</code> problem in a different way. It passes a reference to the original <code>this</code> to every function, which allows you to use some fancy features like prototypal inheritance while still not worrying about binding and the like. If you&#8217;re interested, you can <a href="http://bitbucket.org/jmtulloss/cobra/overview/">find the code on bitbucket</a>.</p>
<h2>Whew</h2>
<p>That&#8217;s pretty much all you need to know about <code>this</code>.</p>
<ul>
<li><code>this</code> will be <code>window</code> whenever your function is indirectly called.</li>
<li>Use <code>apply</code> to force <code>this</code> to be what you want</li>
<li>You can use lexical scoping to make sure <code>this</code> behaves in a predictable manner</li>
</ul>
<p>I hope that&#8217;s clear, comment if it&#8217;s not!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/CaffeinatedSimpleton?a=9-t1xlSNHp0:2ql7pbx-H7s:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/CaffeinatedSimpleton?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/CaffeinatedSimpleton?a=9-t1xlSNHp0:2ql7pbx-H7s:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/CaffeinatedSimpleton?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/CaffeinatedSimpleton?a=9-t1xlSNHp0:2ql7pbx-H7s:3Id5NbicZDU"><img src="http://feeds.feedburner.com/~ff/CaffeinatedSimpleton?i=9-t1xlSNHp0:2ql7pbx-H7s:3Id5NbicZDU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/CaffeinatedSimpleton/~4/9-t1xlSNHp0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://justin.harmonize.fm/index.php/2009/09/an-introduction-to-javascripts-this/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		<feedburner:origLink>http://justin.harmonize.fm/index.php/2009/09/an-introduction-to-javascripts-this/</feedburner:origLink></item>
		<item>
		<title>Meetup.com webOS Client Part 1: Services</title>
		<link>http://feedproxy.google.com/~r/CaffeinatedSimpleton/~3/45qiL0nQ9ro/</link>
		<comments>http://justin.harmonize.fm/index.php/2009/07/meetup-com-webos-client-part-1-services/#comments</comments>
		<pubDate>Mon, 20 Jul 2009 04:46:23 +0000</pubDate>
		<dc:creator>justin</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Example-Meetup-Client]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Meetup.com]]></category>
		<category><![CDATA[Mojo]]></category>
		<category><![CDATA[webOS]]></category>

		<guid isPermaLink="false">http://justin.harmonize.fm/?p=283</guid>
		<description><![CDATA[Palm&#8217;s Mojo SDK has just been released to the public this past week. I thought I would take the opportunity to show off some of the awesome things the SDK can do. The Mojo SDK is exceptionally good at tying your life together with the web services you use every day, so my first series [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://developer.palm.com">Palm&#8217;s Mojo SDK</a> has just been released to the public this past week. I thought I would take the opportunity to show off some of the awesome things the SDK can do. The Mojo SDK is exceptionally good at tying your life together with the web services you use every day, so my first series will be on building a simple Meetup.com client. At first, we&#8217;ll just sync down meetups using the <a href="http://www.meetup.com/meetup_api/key/" target="_blank">api key that&#8217;s associated with every individual account</a>. Another day, we&#8217;ll add OAuth authentication to make it generally useful for anybody.</p>
<p>This article assumes that you have some knowledge of how to create an app, new scenes, and how to debug. If you aren&#8217;t somewhat comfortable with the SDK yet, check out the <a href="http://developer.palm.com/index.php?option=com_content&amp;view=article&amp;id=1758">Hello World tutorial</a>.</p>
<h3>Setup</h3>
<p>At first, we&#8217;ll just create a big button that puts all our meetups into the calendar. Nothing fancy. To create the scene, run:</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">$ palm-generate <span style="color: #660033;">-t</span> new_scene <span style="color: #660033;">-p</span> <span style="color: #ff0000;">&quot;name=sync&quot;</span></pre></div></div>

<p>Then in the stage-assistant.js file, put:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">controller</span>.<span style="color: #660066;">pushScene</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;sync&quot;</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<h3>Creating a Calendar</h3>
<p>The first thing that we will do is create a new calender for Meetup.com. This calendar will appear in the calendar app right next to your Google Calendar or Exchange calendar using the Palm Synergy APIs. This is great because it allows you to deliver new data to your users without having to write yet another way of presenting it. All contacts and calendars can be plugged straight into the core webOS applications.</p>
<p>To create a calendar, you first need to <a href="http://developer.palm.com/index.php?option=com_content&#038;view=article&#038;id=1737">make an account</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">self.<span style="color: #660066;">accountServiceId</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;palm://com.palm.accounts/crud/&quot;</span>;
&nbsp;
 <span style="color: #009966; font-style: italic;">/* Retrieves account if it exists, otherwise creates it */</span>
setupAccount<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>self<span style="color: #339933;">,</span> k<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    self.<span style="color: #660066;">controller</span>.<span style="color: #660066;">serviceRequest</span><span style="color: #009900;">&#40;</span>self.<span style="color: #660066;">accountServiceId</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
        method<span style="color: #339933;">:</span> <span style="color: #3366CC;">'listAccounts'</span><span style="color: #339933;">,</span>
        parameters<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        onSuccess<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>list<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            Mojo.<span style="color: #660066;">Log</span>.<span style="color: #660066;">info</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Got account list: %j&quot;</span><span style="color: #339933;">,</span> list<span style="color: #009900;">&#41;</span>;
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>list.<span style="color: #660066;">list</span> <span style="color: #339933;">&amp;&amp;</span> list.<span style="color: #660066;">list</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> 0<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                self.<span style="color: #660066;">account</span> <span style="color: #339933;">=</span> list.<span style="color: #660066;">list</span><span style="color: #009900;">&#91;</span>0<span style="color: #009900;">&#93;</span>;
                k<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
                self.<span style="color: #660066;">account</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
                    username<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;justin&quot;</span><span style="color: #339933;">,</span>
                    domain<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;meetup.com&quot;</span><span style="color: #339933;">,</span>
                    displayName<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Meetup.com&quot;</span><span style="color: #339933;">,</span>
                    dataTypes<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;CALENDAR&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
                    isDataReadOnly<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
                    icons<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>largeIcon<span style="color: #339933;">:</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">,</span> smallIcon<span style="color: #339933;">:</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#125;</span>
                <span style="color: #009900;">&#125;</span>;
                self.<span style="color: #660066;">controller</span>.<span style="color: #660066;">serviceRequest</span><span style="color: #009900;">&#40;</span>self.<span style="color: #660066;">accountServiceId</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
                    method<span style="color: #339933;">:</span> <span style="color: #3366CC;">'createAccount'</span><span style="color: #339933;">,</span>
                    parameters<span style="color: #339933;">:</span> self.<span style="color: #660066;">account</span><span style="color: #339933;">,</span>
                    onSuccess<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        Mojo.<span style="color: #660066;">Log</span>.<span style="color: #660066;">info</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Got %j for %j&quot;</span><span style="color: #339933;">,</span> response<span style="color: #339933;">,</span> self.<span style="color: #660066;">account</span><span style="color: #009900;">&#41;</span>;
                        self.<span style="color: #660066;">account</span>.<span style="color: #660066;">accountId</span> <span style="color: #339933;">=</span> response.<span style="color: #660066;">accountId</span>;
                        k<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
                    <span style="color: #009900;">&#125;</span>
                <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        onFailure<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            Mojo.<span style="color: #660066;">Controller</span>.<span style="color: #660066;">errorDialog</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Failed to create account&quot;</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #000066;">onError</span><span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>error<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            Mojo.<span style="color: #660066;">Controller</span>.<span style="color: #660066;">errorDialog</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Error creating account&quot;</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span></pre></div></div>

<p>You&#8217;ll notice a few different things about this code, the odd things which are just my style. Using <code>self</code> instead of <code>this</code> is an idiom from <a href="http://bitbucket.org/jmtulloss/cobra/overview/">Cobra</a>, a JavaScript class library I wrote. <code>k</code> is a continuation, or the function that should be called after the account is created. <code>k</code> I believe is an idiom for <a href="http://en.wikipedia.org/wiki/Continuation-passing_style">Continuation Passing Style</a> in <a href="http://en.wikipedia.org/wiki/Scheme_(programming_language)">Scheme</a>.</p>
<p>Beyond that, this is very standard Mojo code. Services are identified as &#8220;palm://com.palm.<service>&#8221; and all methods support <code>onSuccess</code>, <code>onFailure</code>, and <code>onError</code> callbacks. This code checks to see if there is already an account associated with this appId, and if there is, calls its continuation. If there is not, it creates the account and calls its continuation.</p>
<p>After the account is created, we can <a href="http://developer.palm.com/index.php?option=com_content&#038;view=article&#038;id=1751">create the calendar</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">self.<span style="color: #660066;">calendarServiceId</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;palm://com.palm.calendar/crud/&quot;</span>;
&nbsp;
<span style="color: #009966; font-style: italic;">/* Retrieves calendar if it exists, otherwise creates it */</span>
setupCalendar<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>self<span style="color: #339933;">,</span> k<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    self.<span style="color: #660066;">controller</span>.<span style="color: #660066;">serviceRequest</span><span style="color: #009900;">&#40;</span>self.<span style="color: #660066;">calendarServiceId</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
        method<span style="color: #339933;">:</span> <span style="color: #3366CC;">'listCalendars'</span><span style="color: #339933;">,</span>
        parameters<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
            accountId<span style="color: #339933;">:</span> self.<span style="color: #660066;">account</span>.<span style="color: #660066;">accountId</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        onSuccess<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>calList<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            Mojo.<span style="color: #660066;">Log</span>.<span style="color: #660066;">info</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Got calendar list&quot;</span><span style="color: #009900;">&#41;</span>;
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>calList.<span style="color: #660066;">calendars</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> 0<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                self.<span style="color: #660066;">calendar</span> <span style="color: #339933;">=</span> calList.<span style="color: #660066;">calendars</span><span style="color: #009900;">&#91;</span>0<span style="color: #009900;">&#93;</span>;
                k<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
                self.<span style="color: #660066;">calendar</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #000066;">name</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Meetup.com&quot;</span>
                <span style="color: #009900;">&#125;</span>
                self.<span style="color: #660066;">controller</span>.<span style="color: #660066;">serviceRequest</span><span style="color: #009900;">&#40;</span>self.<span style="color: #660066;">calendarServiceId</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
                    method<span style="color: #339933;">:</span> <span style="color: #3366CC;">'createCalendar'</span><span style="color: #339933;">,</span>
                    parameters<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
                        accountId<span style="color: #339933;">:</span> self.<span style="color: #660066;">account</span>.<span style="color: #660066;">accountId</span><span style="color: #339933;">,</span>
                        calendar<span style="color: #339933;">:</span> self.<span style="color: #660066;">calendar</span>
                    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
                    onSuccess<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        self.<span style="color: #660066;">calendar</span>.<span style="color: #660066;">calendarId</span> <span style="color: #339933;">=</span> response.<span style="color: #660066;">calendarId</span>
                        k<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
                    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
                    onFailure<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>error<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        Mojo.<span style="color: #660066;">Log</span>.<span style="color: #660066;">error</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Creating calendar failed: %j&quot;</span><span style="color: #339933;">,</span> error<span style="color: #009900;">&#41;</span>;
                        Mojo.<span style="color: #660066;">Controller</span>.<span style="color: #660066;">errorDialog</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Failed to create calendar&quot;</span><span style="color: #009900;">&#41;</span>;
                    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
                    <span style="color: #000066;">onError</span><span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>error<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        Mojo.<span style="color: #660066;">Log</span>.<span style="color: #660066;">error</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Creating calendar failed: %j&quot;</span><span style="color: #339933;">,</span> error<span style="color: #009900;">&#41;</span>;
                        Mojo.<span style="color: #660066;">Controller</span>.<span style="color: #660066;">errorDialog</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Error creating calendar&quot;</span><span style="color: #009900;">&#41;</span>;
                    <span style="color: #009900;">&#125;</span>
                <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        onFailure<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            Mojo.<span style="color: #660066;">Controller</span>.<span style="color: #660066;">errorDialog</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Failed to create calendar&quot;</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #000066;">onError</span><span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>error<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            Mojo.<span style="color: #660066;">Controller</span>.<span style="color: #660066;">errorDialog</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Error creating calendar&quot;</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span></pre></div></div>

<p>This is almost identical to the account creation code, except it&#8217;s creating a calendar.</p>
<p>Now calling these functions is easy:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">self.<span style="color: #660066;">setupAccount</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    self.<span style="color: #660066;">setupCalendar</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        self.<span style="color: #660066;">buttonModel</span>.<span style="color: #660066;">disabled</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span>;
        self.<span style="color: #660066;">controller</span>.<span style="color: #660066;">modelChanged</span><span style="color: #009900;">&#40;</span>self.<span style="color: #660066;">buttonModel</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<h3>Pulling down events</h3>
<p>To get the events that are associated with the account, I am using the <a href="http://www.meetup.com/meetup_api/clients/">Meetup.com JavaScript client</a>. The client requires jQuery, but since it only requires jQuery to do JSONP, we replace that line with a Mojo call. There is no reason that we couldn&#8217;t use jQuery, but jQuery is overkill for just doing JSONP.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">jQuery.<span style="color: #660066;">getJSON</span><span style="color: #009900;">&#40;</span>urlprefix <span style="color: #339933;">+</span> call_type <span style="color: #339933;">+</span> url<span style="color: #339933;">,</span> params<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>json<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>callback<span style="color: #009900;">&#40;</span>json<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>Becomes:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> query <span style="color: #339933;">=</span> $H<span style="color: #009900;">&#40;</span>params<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toQueryString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
url <span style="color: #339933;">=</span> urlprefix <span style="color: #339933;">+</span> call_type <span style="color: #339933;">+</span> url <span style="color: #339933;">+</span> query;
Mojo.<span style="color: #660066;">loadScriptWithCallback</span><span style="color: #009900;">&#40;</span>url<span style="color: #339933;">,</span> Mojo.<span style="color: #660066;">doNothing</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>After we have the Meetup client library, getting the events is easy, but a little indirect. It takes three API calls, one to get the member id, one to get every group associated with the member id, and one to get every event in all those groups. You can see the details on <a href="http://www.meetup.com/meetup_api/docs/#readmethods">Meetup&#8217;s API page</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">self.<span style="color: #660066;">client</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> MeetupApiClient<span style="color: #009900;">&#40;</span>Meet.<span style="color: #660066;">Auth</span>.<span style="color: #660066;">apiKey</span><span style="color: #009900;">&#41;</span>;
syncCalendar<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>self<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// Gets my member id</span>
    Mojo.<span style="color: #660066;">Log</span>.<span style="color: #660066;">info</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Syncing calendar&quot;</span><span style="color: #009900;">&#41;</span>;
    self.<span style="color: #660066;">client</span>.<span style="color: #660066;">get_members</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
        relation<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;self&quot;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> self._getGroups<span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
_getGroups<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>self<span style="color: #339933;">,</span> members<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    Mojo.<span style="color: #660066;">Log</span>.<span style="color: #660066;">info</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Got members&quot;</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #003366; font-weight: bold;">var</span> memberId <span style="color: #339933;">=</span> members.<span style="color: #660066;">results</span><span style="color: #009900;">&#91;</span>0<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">id</span>;
    self.<span style="color: #660066;">client</span>.<span style="color: #660066;">get_groups</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
        member_id<span style="color: #339933;">:</span> memberId
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> self._getEvents<span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
_getEvents<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>self<span style="color: #339933;">,</span> groups<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    Mojo.<span style="color: #660066;">Log</span>.<span style="color: #660066;">info</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Got events&quot;</span><span style="color: #009900;">&#41;</span>;
    groups <span style="color: #339933;">=</span> groups.<span style="color: #660066;">results</span>;
    <span style="color: #003366; font-weight: bold;">var</span> groupString <span style="color: #339933;">=</span> groups<span style="color: #009900;">&#91;</span>0<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">id</span>;
    <span style="color: #003366; font-weight: bold;">var</span> today <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">1</span>; i <span style="color: #339933;">&lt;</span> groups.<span style="color: #660066;">length</span>; i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        groupString <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&quot;,&quot;</span> <span style="color: #339933;">+</span> groups<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">id</span>;
    <span style="color: #009900;">&#125;</span>
    self.<span style="color: #660066;">client</span>.<span style="color: #660066;">get_events</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
        group_id<span style="color: #339933;">:</span> groupString<span style="color: #339933;">,</span>
        after<span style="color: #339933;">:</span> today.<span style="color: #660066;">getMonth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> today.<span style="color: #660066;">getDay</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> today.<span style="color: #660066;">getFullYear</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> self._saveEvents<span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span></pre></div></div>

<p>Now <code>self._saveEvents</code> will receive a list of events that are coming up after today. All we need to do is loop over the list, format them as Palm calendar events, and pass them to the calendar service.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">_saveEvents<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>self<span style="color: #339933;">,</span> events<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    Mojo.<span style="color: #660066;">Log</span>.<span style="color: #660066;">info</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Saving events&quot;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
    self.<span style="color: #660066;">numEventsProcessed</span> <span style="color: #339933;">=</span> 0;
    self.<span style="color: #660066;">events</span> <span style="color: #339933;">=</span> events;
&nbsp;
    events.<span style="color: #660066;">results</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>meetupEvent<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> time <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span>meetupEvent.<span style="color: #660066;">time</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>meetupEvent.<span style="color: #660066;">myrsvp</span> <span style="color: #339933;">!=</span> <span style="color: #3366CC;">&quot;no&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            self.<span style="color: #660066;">controller</span>.<span style="color: #660066;">serviceRequest</span><span style="color: #009900;">&#40;</span>self.<span style="color: #660066;">calendarServiceId</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
                method<span style="color: #339933;">:</span> <span style="color: #3366CC;">'createEvent'</span><span style="color: #339933;">,</span>
                parameters<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
                    calendarId<span style="color: #339933;">:</span> self.<span style="color: #660066;">calendar</span>.<span style="color: #660066;">calendarId</span><span style="color: #339933;">,</span>
                    event<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
                        eventId<span style="color: #339933;">:</span> meetupEvent.<span style="color: #660066;">id</span><span style="color: #339933;">,</span>
                        subject<span style="color: #339933;">:</span> meetupEvent.<span style="color: #000066;">name</span><span style="color: #339933;">,</span>
                        startTimestamp<span style="color: #339933;">:</span> time<span style="color: #339933;">,</span>
                        endTimestamp<span style="color: #339933;">:</span> time <span style="color: #339933;">+</span> <span style="color: #CC0000;">3600000</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">// 1 hour in ms</span>
                        allDay<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span>
                        note<span style="color: #339933;">:</span> self._formatNote<span style="color: #009900;">&#40;</span>meetupEvent<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                        location<span style="color: #339933;">:</span> meetupEvent.<span style="color: #660066;">lat</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;, &quot;</span> <span style="color: #339933;">+</span> meetupEvent.<span style="color: #660066;">lon</span><span style="color: #339933;">,</span>
                        alarm<span style="color: #339933;">:</span> <span style="color: #3366CC;">'none'</span><span style="color: #339933;">,</span>
                    <span style="color: #009900;">&#125;</span>
                <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
                onSuccess<span style="color: #339933;">:</span> self._createdEvent<span style="color: #339933;">,</span>
                <span style="color: #000066;">onError</span><span style="color: #339933;">:</span> self._errorCreatingEvent<span style="color: #339933;">,</span>
                onFailure<span style="color: #339933;">:</span> self._failureCreatingEvent
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
_createdEvent<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>self<span style="color: #339933;">,</span> response<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    self._checkIfSyncFinished<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
_errorCreatingEvent<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>self<span style="color: #339933;">,</span> response<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    Mojo.<span style="color: #660066;">Log</span>.<span style="color: #660066;">error</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Could not create event: %j&quot;</span><span style="color: #339933;">,</span> response<span style="color: #009900;">&#41;</span>;
    self._checkIfSyncFinished<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
_failureCreatingEvent<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>self<span style="color: #339933;">,</span> response<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    Mojo.<span style="color: #660066;">Log</span>.<span style="color: #660066;">error</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Failed to create event: %d, %j&quot;</span><span style="color: #339933;">,</span> self._eventsReturned<span style="color: #339933;">,</span> response<span style="color: #009900;">&#41;</span>;
    self._checkIfSyncFinished<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
_checkIfSyncFinished<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>self<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    self.<span style="color: #660066;">numEventsProcessed</span>++;
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>self.<span style="color: #660066;">numEventsProcessed</span> <span style="color: #339933;">==</span> self.<span style="color: #660066;">events</span>.<span style="color: #660066;">meta</span>.<span style="color: #660066;">count</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>self.<span style="color: #660066;">events</span>.<span style="color: #660066;">meta</span>.<span style="color: #660066;">next</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            Mojo.<span style="color: #660066;">Log</span>.<span style="color: #660066;">info</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Fetching the next page of results...&quot;</span><span style="color: #009900;">&#41;</span>;
            self.<span style="color: #660066;">client</span>.<span style="color: #660066;">nextPage</span><span style="color: #009900;">&#40;</span>self._saveEvents<span style="color: #009900;">&#41;</span>;
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
            Mojo.<span style="color: #660066;">Log</span>.<span style="color: #660066;">info</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Fetched all the events&quot;</span><span style="color: #009900;">&#41;</span>;
            self.<span style="color: #660066;">buttonModel</span>.<span style="color: #660066;">disabled</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span>;
            self.<span style="color: #660066;">controller</span>.<span style="color: #660066;">modelChanged</span><span style="color: #009900;">&#40;</span>self.<span style="color: #660066;">buttonModel</span><span style="color: #009900;">&#41;</span>;
            self.<span style="color: #660066;">controller</span>.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;sync-button&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">mojo</span>.<span style="color: #660066;">deactivate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span></pre></div></div>

<p>And that&#8217;s basically it! With the code above, all your Meetup.com events can be inserted into your webOS calendar. All you need is an event handler for your button.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">self.<span style="color: #660066;">buttonModel</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
    buttonLabel<span style="color: #339933;">:</span> <span style="color: #3366CC;">'Sync'</span><span style="color: #339933;">,</span>
    disabled<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span>
<span style="color: #009900;">&#125;</span>;
&nbsp;
self.<span style="color: #660066;">controller</span>.<span style="color: #660066;">setupWidget</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'sync-button'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
    type<span style="color: #339933;">:</span> Mojo.<span style="color: #660066;">Widget</span>.<span style="color: #660066;">activityButton</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> self.<span style="color: #660066;">buttonModel</span><span style="color: #009900;">&#41;</span>;
&nbsp;
Mojo.<span style="color: #660066;">Event</span>.<span style="color: #660066;">listen</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'sync-button'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> Mojo.<span style="color: #660066;">Event</span>.<span style="color: #660066;">tap</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    self.<span style="color: #660066;">buttonModel</span>.<span style="color: #660066;">disabled</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span>;
    self.<span style="color: #660066;">controller</span>.<span style="color: #660066;">modelChanged</span><span style="color: #009900;">&#40;</span>self.<span style="color: #660066;">buttonModel</span><span style="color: #009900;">&#41;</span>
    self.<span style="color: #660066;">controller</span>.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;sync-button&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">mojo</span>.<span style="color: #660066;">activate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
    self.<span style="color: #660066;">syncCalendar</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>This works assuming a view containing:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;div x-mojo-element=&quot;Button&quot; id=&quot;sync-button&quot;&gt;&lt;/div&gt;</pre></div></div>

<h3>Debugging Tips</h3>
<p>Creating a file called <code>framework_config.json</code> allows you to change the logging level. That will permit JavaScript messages to be output into /var/log/messages on the device. This is especially valuable if you&#8217;re working on a 64-bit linux machine where the inspector is currently not supported.</p>

<div class="wp_syntax"><div class="code"><pre class="json" style="font-family:monospace;">{
    &quot;logLevel&quot;: 99 // 0 means no logging, 99 will max it out
}</pre></div></div>

<p>Removing /var/luna/data/dbdata/PalmDatabase.db3 removes all data you may have inserted. This allows you to start over fresh, but I wouldn&#8217;t recommend doing this on your actual device. You&#8217;ll lose all your data!</p>
<h3>Todo</h3>
<p>This program isn&#8217;t really complete, but it&#8217;s a good start. A couple of things we still have to do are:</p>
<ul>
<li>Add Authentication with OAuth</li>
<li>Keep track of already inserted appointments so we don&#8217;t insert duplicates</li>
<li>Add automatic synchronization in the background</li>
<li>Add push updates (this is impossible without server side support)</li>
<li>Make things look nice</li>
</ul>
<p>Stay tuned for articles on some or all of these exciting new features! Until then, the <a href="http://github.com/jmtulloss/Meetup.com-Mojo-Client/tree/Services">code is available on github</a>.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/CaffeinatedSimpleton?a=45qiL0nQ9ro:9hzNTUHDykE:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/CaffeinatedSimpleton?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/CaffeinatedSimpleton?a=45qiL0nQ9ro:9hzNTUHDykE:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/CaffeinatedSimpleton?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/CaffeinatedSimpleton?a=45qiL0nQ9ro:9hzNTUHDykE:3Id5NbicZDU"><img src="http://feeds.feedburner.com/~ff/CaffeinatedSimpleton?i=45qiL0nQ9ro:9hzNTUHDykE:3Id5NbicZDU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/CaffeinatedSimpleton/~4/45qiL0nQ9ro" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://justin.harmonize.fm/index.php/2009/07/meetup-com-webos-client-part-1-services/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		<feedburner:origLink>http://justin.harmonize.fm/index.php/2009/07/meetup-com-webos-client-part-1-services/</feedburner:origLink></item>
	</channel>
</rss>
