<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	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/"
	>

<channel>
	<title>Neyric.com &#187; timer</title>
	<atom:link href="http://neyric.com/tag/timer/feed/" rel="self" type="application/rss+xml" />
	<link>http://neyric.com</link>
	<description>projects, programming, blogging...</description>
	<lastBuildDate>Sat, 29 Jan 2011 19:51:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>How to set a timer within an object in Javascript</title>
		<link>http://neyric.com/2007/02/01/how-to-set-a-timer-within-an-object-in-javascript/</link>
		<comments>http://neyric.com/2007/02/01/how-to-set-a-timer-within-an-object-in-javascript/#comments</comments>
		<pubDate>Thu, 01 Feb 2007 13:50:54 +0000</pubDate>
		<dc:creator>neyric</dc:creator>
				<category><![CDATA[setTimeout]]></category>
		<category><![CDATA[timer]]></category>

		<guid isPermaLink="false">http://javascript.neyric.com/blog/?p=35</guid>
		<description><![CDATA[UPDATE: I don&#8217;t recommend this method anymore: it&#8217;s not a good idea to add functions to Object.prototype. Prefer adding this function to your object prototypes. Here&#8217;s a useful method given by Douglas Crockford that can be added to Object.prototype : &#8230; <a href="http://neyric.com/2007/02/01/how-to-set-a-timer-within-an-object-in-javascript/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p><em> <strong>UPDATE</strong>: I don&#8217;t recommend this method anymore: it&#8217;s not a good idea to add functions to Object.prototype. Prefer adding this function to your object prototypes.</em></p>
<p>Here&#8217;s a useful method given by <a href="http://javascript.crockford.com/" target="_blank">Douglas Crockford</a> that can be added to Object.prototype :</p>
<pre>
Object.prototype.later = function( msec, method) {
  var that = this;
  var args = Array.prototype.slice.apply( arguments, [2] );

  if( typeof method === 'string' ) {
    method = that[method];
 }
  setTimeout(function() {
    method.apply(that, args);
  }, msec);

  return that;
};</pre>
<p>Then, you can call it on any object, the function will be called with the object scope:</p>
<pre>
myObject.later(1000, "methodName", arg1, arg2, .... ); // call myObject.methodName(arg1, arg2) in 1 second</pre>
<div class="shr-publisher-35"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://neyric.com/2007/02/01/how-to-set-a-timer-within-an-object-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

