<?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>南芝 - 我才12岁（飞鸟尽，良弓藏，2011，背包去旅行！） &#187; batch</title>
	<atom:link href="http://www.12sui.cn/tag/batch/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.12sui.cn</link>
	<description>南芝的前端技术学习经验</description>
	<lastBuildDate>Sun, 08 Jan 2012 09:22:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
		<item>
		<title>YAHOO.util.Dom.batch</title>
		<link>http://www.12sui.cn/develop/yahoo-util-dom-batch/</link>
		<comments>http://www.12sui.cn/develop/yahoo-util-dom-batch/#comments</comments>
		<pubDate>Sat, 28 Mar 2009 12:37:13 +0000</pubDate>
		<dc:creator>南芝</dc:creator>
				<category><![CDATA[编码]]></category>
		<category><![CDATA[batch]]></category>
		<category><![CDATA[YUI]]></category>

		<guid isPermaLink="false">http://www.12sui.cn/?p=297</guid>
		<description><![CDATA[就在刚刚，带着梦想，我去了影院，结果还是晚了一步。。。其实我有两个目标，一个是《东邪西毒》终极版，一个是《贫民窟的百万富翁》，然而到了影院我发现《东邪西毒》的票价竟然是100元。。。远远超过了我的心里承受能力，所以我放弃了，另一个《贫民窟的百万富翁》票价是50元，还能接受，可是已经在19点05分上映了。。我去的时间已经晚了十几分钟，而下一场的时间是20点25分，我想了想，等看完了，就太晚了，所以我毅然决定返回，只听嗖的一声，我飞了回来。继续YUI。。。 YUI的Dom方法中的batch促成了大多数其他Dom方法的el可以使用数组，功劳不小哦~现在来看看batch方法： batch: function(el, method, o, overrides) { var collection = [], scope = (overrides) ? o : window; el = (el &#38;&#38; (el[TAG_NAME] &#124;&#124; el.item)) ? el : Y.Dom.get(el); // skip get() when possible if (el &#38;&#38; method) { if (el[TAG_NAME] &#124;&#124; el.length === undefined) { // element or not array-like return method.call(scope, el, [...]]]></description>
			<content:encoded><![CDATA[<p>就在刚刚，带着梦想，我去了影院，结果还是晚了一步。。。其实我有两个目标，一个是《东邪西毒》终极版，一个是《贫民窟的百万富翁》，然而到了影院我发现《东邪西毒》的票价竟然是100元。。。远远超过了我的心里承受能力，所以我放弃了，另一个《贫民窟的百万富翁》票价是50元，还能接受，可是已经在19点05分上映了。。我去的时间已经晚了十几分钟，而下一场的时间是20点25分，我想了想，等看完了，就太晚了，所以我毅然决定返回，只听嗖的一声，我飞了回来。继续YUI。。。</p>

<p>YUI的Dom方法中的batch促成了大多数其他Dom方法的el可以使用数组，功劳不小哦~现在来看看batch方法：</p>

<p><pre>batch: function(el, method, o, overrides) {
            var collection = [],
                scope = (overrides) ? o : window;</p>

<pre><code>        el = (el &amp;&amp; (el[TAG_NAME] || el.item)) ? el : Y.Dom.get(el); // skip get() when possible
        if (el &amp;&amp; method) {
            if (el[TAG_NAME] || el.length === undefined) { // element or not array-like 
                return method.call(scope, el, o);
            } 

            for (var i = 0; i &lt; el.length; ++i) {
                collection[collection.length] = method.call(scope, el[i], o);
            }
        } else {
            YAHOO.log('batch called with invalid arguments', 'warn', 'Dom');
            return false;
        } 
        return collection;
    }&lt;/pre&gt;
</code></pre>

<p>应该是比较好理解，如果el是id或者单节点的话，就直接返回，如果是数组的话就循环一下，最后输出数组。</p>

<p><span id="more-297"></span></p>

<p>可能但看这个不是很好理解，那么看个例子吧：</p>

<p><pre>setStyle: function(el, property, val) {
            Y.Dom.batch(el, Y.Dom._setStyle, { prop: property, val: val });
        },</p>

<pre><code>    _setStyle: function() {
        if (isIE) {
            return function(el, args) {
                var property = Y.Dom._toCamel(args.prop),
                    val = args.val;

                if (el) {
                    switch (property) {
                        case 'opacity':
                            if ( lang.isString(el.style.filter) ) { // in case not appended
                                el.style.filter = 'alpha(opacity=' + val * 100 + ')';

                                if (!el[CURRENT_STYLE] || !el[CURRENT_STYLE].hasLayout) {
                                    el.style.zoom = 1; // when no layout or cant tell
                                }
                            }
                            break;
                        case 'float':
                            property = 'styleFloat';
                        default:
                        el.style[property] = val;
                    }
                } else {
                    YAHOO.log('element ' + el + ' is undefined', 'error', 'Dom');
                }
            };
        } else {
            return function(el, args) {
                var property = Y.Dom._toCamel(args.prop),
                    val = args.val;
                if (el) {
                    if (property == 'float') {
                        property = 'cssFloat';
                    }
                    el.style[property] = val;
                } else {
                    YAHOO.log('element ' + el + ' is undefined', 'error', 'Dom');
                }
            };
        }

    }()&lt;/pre&gt;
</code></pre>

<p>我们可以看到setStyle里使用了Y.Dom.batch(el, Y.Dom._setStyle, { prop: property, val: val });，很容易理解吧哈。。。也不晓得该怎么解释。。就这样吧哈。。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.12sui.cn/develop/yahoo-util-dom-batch/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

