<?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>浮山狼de博客 &#187; javas</title>
	<atom:link href="https://www.fushanlang.com/tag/javas/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.fushanlang.com</link>
	<description>next station - 下一站，活在当下，且行且思</description>
	<lastBuildDate>Sat, 29 Nov 2014 15:14:11 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.2.5</generator>
	<item>
		<title>最轻巧的javascript模板函数</title>
		<link>https://www.fushanlang.com/the-most-lightweight-javascript-template-function-2321/</link>
		<comments>https://www.fushanlang.com/the-most-lightweight-javascript-template-function-2321/#comments</comments>
		<pubDate>Sun, 29 Sep 2013 10:26:27 +0000</pubDate>
		<dc:creator><![CDATA[fushanlang]]></dc:creator>
				<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[javas]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://www.fushanlang.com/blog/?p=2321</guid>
		<description><![CDATA[<p>随着移动互联网的发展APP站点增加，ajax数据交互变得频繁起来，许多javascript 模板终于有了用武之地。</p> <p>看过一些js模板引擎，引入很多语法，解析，使得模板字符串看上去更漂亮，更接近UI，去程序化是他们的目的。</p> <p>两年前自己也写了一个js template函数在项目中使用，今天精简了一下语法，增加error report功能方便了模板解析出错时定位问题。</p> <p>本着开源的精神，我把它放到了github上 https://github.com/fushanlang/js-template</p> <p>以及 oschina开源库里</p> <p>http://git.oschina.net/fushanlang/javascript-template</p> function js_template(t, v) { var a = ""; var echo = function (b) { a += b }; var z = window.AJ; window.AJ = z = !z ? [] : z; var s = "_{" + Math.random() + "}_"; var p = t.replace(/\n&#124;\r&#124;\t/g, <span style="color:#777"> . . . &#8594; Read More: <a href="https://www.fushanlang.com/the-most-lightweight-javascript-template-function-2321/">最轻巧的javascript模板函数</a></span>]]></description>
				<content:encoded><![CDATA[<p>随着移动互联网的发展APP站点增加，ajax数据交互变得频繁起来，许多javascript 模板终于有了用武之地。</p>
<p>看过一些js模板引擎，引入很多语法，解析，使得模板字符串看上去更漂亮，更接近UI，去程序化是他们的目的。</p>
<p>两年前自己也写了一个js template函数在项目中使用，今天精简了一下语法，增加error report功能方便了模板解析出错时定位问题。</p>
<p>本着开源的精神，我把它放到了github上<br />
<a title="js-template" href="https://github.com/fushanlang/js-template" target="_blank">https://github.com/fushanlang/js-template</a></p>
<p>以及 oschina开源库里</p>
<p><a href="http://git.oschina.net/fushanlang/javascript-template" target="_blank">http://git.oschina.net/fushanlang/javascript-template</a></p>
<pre name="code" class="javascript">
function js_template(t, v) {
    var a = "";
    var echo = function (b) {
        a += b
    };
    var z = window.AJ;
    window.AJ = z = !z ? [] : z;
    var s = "_{" + Math.random() + "}_";
    var p = t.replace(/\n|\r|\t/g, "");
    var j = [];
    p = p.replace(/<js>(.*?)<\/js>/g, function ($0, $1) {
        j.push($1);
        return s
    });
    var txt = p.split(s);
    p = "";
    for (var i = 0; i < j.length; ++i) {
        p += "echo(txt[" + i + "]);";
        p += j[i]
    }
    ;
    p += "echo(txt[" + j.length + "]);";
    try {
        if (v) {
            for (var i in v) {
                eval("var " + i + " =v[i];")
            }
        }
        ;
        eval(p)
    } catch (error) {
        z.push([error, p, t])
    } finally {
        return a
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>https://www.fushanlang.com/the-most-lightweight-javascript-template-function-2321/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
