<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.0.4" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: Useful Utility Functions in mootools</title>
	<link>http://www.coryhudson.com/blog/2006/09/14/useful-utility-functions-in-mootools/</link>
	<description>Working smarter, not harder</description>
	<pubDate>Sat, 19 Jul 2008 19:06:37 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.4</generator>

	<item>
		<title>by: Steve</title>
		<link>http://www.coryhudson.com/blog/2006/09/14/useful-utility-functions-in-mootools/#comment-7652</link>
		<pubDate>Mon, 16 Jul 2007 12:35:12 +0000</pubDate>
		<guid>http://www.coryhudson.com/blog/2006/09/14/useful-utility-functions-in-mootools/#comment-7652</guid>
					<description>In prototype in the PeriodicalUpdater function, there is an option called decay that lets the call frequency "decay" if the result does not change from one call to the next. Is anyone aware whether this functionality exists in mootools Periodical?

I just discovered mootools and js frameworks on the whole, and i'm keen to use mootools due to everything mentioned above...</description>
		<content:encoded><![CDATA[<p>In prototype in the PeriodicalUpdater function, there is an option called decay that lets the call frequency &#8220;decay&#8221; if the result does not change from one call to the next. Is anyone aware whether this functionality exists in mootools Periodical?</p>
<p>I just discovered mootools and js frameworks on the whole, and i&#8217;m keen to use mootools due to everything mentioned above&#8230;
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: airtonix</title>
		<link>http://www.coryhudson.com/blog/2006/09/14/useful-utility-functions-in-mootools/#comment-368</link>
		<pubDate>Sat, 07 Oct 2006 17:52:20 +0000</pubDate>
		<guid>http://www.coryhudson.com/blog/2006/09/14/useful-utility-functions-in-mootools/#comment-368</guid>
					<description>wow, [runs off to change pants]

[looks at mate] did you see those response times? freakin awesome!!!!</description>
		<content:encoded><![CDATA[<p>wow, [runs off to change pants]</p>
<p>[looks at mate] did you see those response times? freakin awesome!!!!
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Nigel</title>
		<link>http://www.coryhudson.com/blog/2006/09/14/useful-utility-functions-in-mootools/#comment-350</link>
		<pubDate>Wed, 04 Oct 2006 16:26:12 +0000</pubDate>
		<guid>http://www.coryhudson.com/blog/2006/09/14/useful-utility-functions-in-mootools/#comment-350</guid>
					<description>Cory, please keep up with the articles, I like the look of mootools as a route into learning OO JS rather than trad functional programming, but documentation is a bit thin so far so your pieces are very welcome.

You obviously know what you are talking about so maybe you could explain something very simple to me (it's the abstract of OO vs the specifics of functional programming that is confusing me).

If, as in one of Valerio's tutorials which I've copied some of below, a div is created which has its properties defined in a stylesheet, I can 

	fx.Background = Class.create();
		fx.Background.prototype = Object.extend(new fx.Base(), {
			initialize: function(el, options) {
				this.el = $(el);
				alert( ... );
				this.setOptions(options);
				this.now = 0;
			}, ...
		);

		window.onload = function() {
			myNewEffect = new fx.Background('examplescrolling', {duration: 500});
		}

I added the alert box there. I can get some properties there eg this.el.offsetHeight will return the correct value, but none of the style properties are available, eg this.el.style.top doesn't return anything. I can set style properties there but not read them (ie from the stylesheet declarations). It is such a fundamental problem I'm assuming the answer is really simple.. ;-)</description>
		<content:encoded><![CDATA[<p>Cory, please keep up with the articles, I like the look of mootools as a route into learning OO JS rather than trad functional programming, but documentation is a bit thin so far so your pieces are very welcome.</p>
<p>You obviously know what you are talking about so maybe you could explain something very simple to me (it&#8217;s the abstract of OO vs the specifics of functional programming that is confusing me).</p>
<p>If, as in one of Valerio&#8217;s tutorials which I&#8217;ve copied some of below, a div is created which has its properties defined in a stylesheet, I can </p>
<p>	fx.Background = Class.create();<br />
		fx.Background.prototype = Object.extend(new fx.Base(), {<br />
			initialize: function(el, options) {<br />
				this.el = $(el);<br />
				alert( &#8230; );<br />
				this.setOptions(options);<br />
				this.now = 0;<br />
			}, &#8230;<br />
		);</p>
<p>		window.onload = function() {<br />
			myNewEffect = new fx.Background(&#8217;examplescrolling&#8217;, {duration: 500});<br />
		}</p>
<p>I added the alert box there. I can get some properties there eg this.el.offsetHeight will return the correct value, but none of the style properties are available, eg this.el.style.top doesn&#8217;t return anything. I can set style properties there but not read them (ie from the stylesheet declarations). It is such a fundamental problem I&#8217;m assuming the answer is really simple.. <img src='http://www.coryhudson.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Valerio Proietti</title>
		<link>http://www.coryhudson.com/blog/2006/09/14/useful-utility-functions-in-mootools/#comment-212</link>
		<pubDate>Wed, 20 Sep 2006 14:15:05 +0000</pubDate>
		<guid>http://www.coryhudson.com/blog/2006/09/14/useful-utility-functions-in-mootools/#comment-212</guid>
					<description>@Yaroslaff "Inviz" Fedin: The function is now there, and its called pass. Its a shortcut to create anonymous functions that contains calls to actual functions with parameters. example:

before:
&lt;code&gt;

$('myelement').onclick = function(){
    $('myElement').addClassName('myClass');
};

&lt;/code&gt;

after:

&lt;code&gt; 
$('myElement').onclick = $('myElement').addClassName.pass('myClass');
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>@Yaroslaff &#8220;Inviz&#8221; Fedin: The function is now there, and its called pass. Its a shortcut to create anonymous functions that contains calls to actual functions with parameters. example:</p>
<p>before:<br />
<code></p>
<p>$('myelement').onclick = function(){<br />
    $('myElement').addClassName('myClass');<br />
};</p>
<p></code></p>
<p>after:</p>
<p><code><br />
$('myElement').onclick = $('myElement').addClassName.pass('myClass');<br />
</code>
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Steffen</title>
		<link>http://www.coryhudson.com/blog/2006/09/14/useful-utility-functions-in-mootools/#comment-165</link>
		<pubDate>Fri, 15 Sep 2006 15:51:05 +0000</pubDate>
		<guid>http://www.coryhudson.com/blog/2006/09/14/useful-utility-functions-in-mootools/#comment-165</guid>
					<description>try this:
[code]
var $break = new Object();
try{
  [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].each(
    function(x){
      if(x  8) throw $break;
      alert(x);})
}catch(e){
  if(e != $break) throw e;
}
[/code]
This alert all numbers from 5 to 8, but won't run the function for the value 10, cause using "throw $break" we've finished looping earlier...
This is, what Prototype uses whenever you call .each...
we may make it more readable:
[code]
var $break = new Object();
function break(){ throw $break; }
Array.prototype.myEach = function(fn, bind){
  try{ this.each(fn, bind); }catch(e){ if(e != $break) throw e; }}

//and finally write:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10].myEach(
  function(x){
    if(x  8) break();
    alert(x);
});
[/code]
Now you may use .myEach, if you need looping with break and each if you don't need to break out of a loop...</description>
		<content:encoded><![CDATA[<p>try this:<br />
[code]<br />
var $break = new Object();<br />
try{<br />
  [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].each(<br />
    function(x){<br />
      if(x  <img src='http://www.coryhudson.com/blog/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' />  throw $break;<br />
      alert(x);})<br />
}catch(e){<br />
  if(e != $break) throw e;<br />
}<br />
[/code]<br />
This alert all numbers from 5 to 8, but won&#8217;t run the function for the value 10, cause using &#8220;throw $break&#8221; we&#8217;ve finished looping earlier&#8230;<br />
This is, what Prototype uses whenever you call .each&#8230;<br />
we may make it more readable:<br />
[code]<br />
var $break = new Object();<br />
function break(){ throw $break; }<br />
Array.prototype.myEach = function(fn, bind){<br />
  try{ this.each(fn, bind); }catch(e){ if(e != $break) throw e; }}</p>
<p>//and finally write:<br />
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10].myEach(<br />
  function(x){<br />
    if(x  <img src='http://www.coryhudson.com/blog/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' />  break();<br />
    alert(x);<br />
});<br />
[/code]<br />
Now you may use .myEach, if you need looping with break and each if you don&#8217;t need to break out of a loop&#8230;
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Yaroslaff "Inviz" Fedin</title>
		<link>http://www.coryhudson.com/blog/2006/09/14/useful-utility-functions-in-mootools/#comment-150</link>
		<pubDate>Thu, 14 Sep 2006 22:26:46 +0000</pubDate>
		<guid>http://www.coryhudson.com/blog/2006/09/14/useful-utility-functions-in-mootools/#comment-150</guid>
					<description>you cant emulate break, but continue. return will act only as continue. 
You can set a check, but it wont be the same.</description>
		<content:encoded><![CDATA[<p>you cant emulate break, but continue. return will act only as continue.<br />
You can set a check, but it wont be the same.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Steffen</title>
		<link>http://www.coryhudson.com/blog/2006/09/14/useful-utility-functions-in-mootools/#comment-149</link>
		<pubDate>Thu, 14 Sep 2006 22:15:35 +0000</pubDate>
		<guid>http://www.coryhudson.com/blog/2006/09/14/useful-utility-functions-in-mootools/#comment-149</guid>
					<description>[quote]
What, you’re not using break and continue statements? They can really help you cut down on loop iterations. There is no way to use break or continue in an each loop in mootools, so keep that in mind. You’ll have to use the good old-fashioned for loop for that one.
[/quote]
You don't realy need to use the for loop in that case...
If You wan't to "emulate" the continue statement just use "return" inside your function (since .each uses a function and not  a block this feels more natural for me and using "throw $break" feels kinda stupid)
If you need a break statement you can easily emulate it using try/catch like prototype does (writing an extra function to abstract the try/catch block away will be very easy)
e.g.
[1, 2, 3].each(
  function(x){
    if(x == 2) return; 
    else alert(x);})</description>
		<content:encoded><![CDATA[<p>[quote]<br />
What, you’re not using break and continue statements? They can really help you cut down on loop iterations. There is no way to use break or continue in an each loop in mootools, so keep that in mind. You’ll have to use the good old-fashioned for loop for that one.<br />
[/quote]<br />
You don&#8217;t realy need to use the for loop in that case&#8230;<br />
If You wan&#8217;t to &#8220;emulate&#8221; the continue statement just use &#8220;return&#8221; inside your function (since .each uses a function and not  a block this feels more natural for me and using &#8220;throw $break&#8221; feels kinda stupid)<br />
If you need a break statement you can easily emulate it using try/catch like prototype does (writing an extra function to abstract the try/catch block away will be very easy)<br />
e.g.<br />
[1, 2, 3].each(<br />
  function(x){<br />
    if(x == 2) return;<br />
    else alert(x);})
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Yaroslaff "Inviz" Fedin</title>
		<link>http://www.coryhudson.com/blog/2006/09/14/useful-utility-functions-in-mootools/#comment-148</link>
		<pubDate>Thu, 14 Sep 2006 21:53:51 +0000</pubDate>
		<guid>http://www.coryhudson.com/blog/2006/09/14/useful-utility-functions-in-mootools/#comment-148</guid>
					<description>Yeah, Cory, It looks like Valerio removed define method from function.js. He prolly had a good reason for this. But without eval i'd do it like this:

&lt;code&gt;
	define: function(a,b,c,d,e,f,g,h,i,j) {
		return (function(){this(a,b,d,c,d,e,f,g,h,i,j);});
	}
&lt;/code&gt;

which just does dirty job for you.</description>
		<content:encoded><![CDATA[<p>Yeah, Cory, It looks like Valerio removed define method from function.js. He prolly had a good reason for this. But without eval i&#8217;d do it like this:</p>
<p><code><br />
	define: function(a,b,c,d,e,f,g,h,i,j) {<br />
		return (function(){this(a,b,d,c,d,e,f,g,h,i,j);});<br />
	}<br />
</code></p>
<p>which just does dirty job for you.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Cory Hudson</title>
		<link>http://www.coryhudson.com/blog/2006/09/14/useful-utility-functions-in-mootools/#comment-146</link>
		<pubDate>Thu, 14 Sep 2006 18:40:12 +0000</pubDate>
		<guid>http://www.coryhudson.com/blog/2006/09/14/useful-utility-functions-in-mootools/#comment-146</guid>
					<description>@Yaroslaff: The define function looks handy. It looks like it's for binding arguments to a function, like currying and partial application. Is this correct? I've looked through the latest mootools release and can't find the define method anywhere. Is this a feature coming soon? It would really come in handy.</description>
		<content:encoded><![CDATA[<p>@Yaroslaff: The define function looks handy. It looks like it&#8217;s for binding arguments to a function, like currying and partial application. Is this correct? I&#8217;ve looked through the latest mootools release and can&#8217;t find the define method anywhere. Is this a feature coming soon? It would really come in handy.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Yaroslaff "Inviz" Fedin</title>
		<link>http://www.coryhudson.com/blog/2006/09/14/useful-utility-functions-in-mootools/#comment-140</link>
		<pubDate>Thu, 14 Sep 2006 11:51:34 +0000</pubDate>
		<guid>http://www.coryhudson.com/blog/2006/09/14/useful-utility-functions-in-mootools/#comment-140</guid>
					<description>Cory, there's also a define function, that allows to use delay &#38; function with arguments without lambda

function myfunc(f) {
alert(f);
}
myfunc.define('sup').delay(600);

not sure in syntax right now.</description>
		<content:encoded><![CDATA[<p>Cory, there&#8217;s also a define function, that allows to use delay &amp; function with arguments without lambda</p>
<p>function myfunc(f) {<br />
alert(f);<br />
}<br />
myfunc.define(&#8217;sup&#8217;).delay(600);</p>
<p>not sure in syntax right now.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Bruno Figueiredo</title>
		<link>http://www.coryhudson.com/blog/2006/09/14/useful-utility-functions-in-mootools/#comment-138</link>
		<pubDate>Thu, 14 Sep 2006 09:59:38 +0000</pubDate>
		<guid>http://www.coryhudson.com/blog/2006/09/14/useful-utility-functions-in-mootools/#comment-138</guid>
					<description>Nice post. Very useful. I've also posted on how to create a &lt;a href="http://www.brunofigueiredo.com/archive/2006/09/14/88.aspx" rel="nofollow"&gt;simple lightBox example&lt;/a&gt; using the new mooTools.</description>
		<content:encoded><![CDATA[<p>Nice post. Very useful. I&#8217;ve also posted on how to create a <a href="http://www.brunofigueiredo.com/archive/2006/09/14/88.aspx" rel="nofollow">simple lightBox example</a> using the new mooTools.
</p>
]]></content:encoded>
				</item>
</channel>
</rss>
