新足迹

 找回密码
 注册

精华好帖回顾

· The Prom 2011 (2011-11-1) 0.01 · 20种美容小秘方 (2005-1-14) elin
· 园艺 -- -- 玫瑰(中) (2009-4-1) ham · 回国(上海)有感(PATRICKZHU) (2007-10-25) patrickzhu
Advertisement
Advertisement
查看: 1330|回复: 1

Douglas 最新推出JSDev, 大家看看怎么用? [复制链接]

发表于 2012-1-9 15:33 |显示全部楼层
此文章由 典 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 典 所有!转贴必须注明作者、出处和本声明,并保持内容完整
Douglas 是javascript 标准委员会成员,

https://github.com/douglascrockford/JSDev

JSDev, 大意是做js开发的时候写些comment, 在debug的时候这些comment也会运行,minify后些comments会消失。这个思路类似于.net里的一些东西。

看了半天不知道怎么用,

Douglas Crockford
douglas@crockford.com

2012-01-05

JSDev is a filter that activates selected comments, making them executable.
This makes it possible to put development, performance, and testing scaffolding,
into a source file. The scaffolding is removed by minification, but is activated
by JSDev.

JSDev is a filter that takes a source file and looks for tagged comments in
either ofthese forms:

    /*<tag> <stuff>*/

    /*<tag>(<condition>) <stuff>*/

There can be no space between the /* and the <tag>. There can be no space
between the <tag> and the (. The content of tagged comment may not include
comments, nor can it contain strings or regular expression literals that
contain */. So, write

    /*debug(/[a-z][a-z0-9]*/.test(variable))
        console.log("*/ test");
    */

as

    /*debug(/[a-z][a-z0-9]*(?:)/.test(variable))
        console.log("*\/ test");
    */

JSDev is given a list the names of the tags that should be activated.
Also, methods can be defined by following the tag name with : and a method
name. There can be no spaces around the :.

    Replacement     /*<tag>         */

    tag form        {               }
    method form     {<method>(      );}

If a condition was included, then the replacement will be preceeded with an
if statement.

The implementation in C obtains the input from stdin, and provides the result
to stdout. The tag list is taken from the command line. The command line can
also include a -comment specification. It will exit(1) if there is an error.

In JavaScript, it is available as the JSDEV function that takes a source,
an array of tags, and an optional array of comments. It will throw an
exception if there is an error.

Example:

    jsdev -comment "Devel Edition." <input >output test_expose enter:trace.enter exit:trace.exit unless:alert

JavaScript:

    output = JSDEV(input, [
        "test_expose",
        "enter:trace.enter",
        "exit:trace.exit",
        "unless:alert"
    ] , ["Devel Edition."]);

input:

    // This is a sample file.

    function Constructor(number) {
        /*enter 'Constructor'*/
        /*unless(typeof number !== 'number') 'number', "Type error"*/
        function private_method() {
            /*enter 'private_method'*/
            /*exit 'private_method'*/
        }
        /*test_expose
            this.private_method = private_method;
        */
        this.priv = function () {
            /*enter 'priv'*/
            private_method();
            /*exit 'priv'*/
        }
        /*exit "Constructor"*/
    }

output:

    // Devel Edition.
    // This is a sample file.

    function Constructor(number) {
        {trace.enter('Constructor');}
        if (typeof number !== 'number') {alert('number', "Type error");}
        function private_method() {
            {trace.enter('private_method');}
            {trace.exit('private_method');}
        }
        {
            this.private_method = private_method;
        }
        this.priv = function () {
            {trace.enter('priv');}
            private_method();
            {trace.exit('priv');}
        }
        {trace.exit("Constructor");}
    }

lightly minified:

    function Constructor(number) {
        function private_method() {
        }
        this.priv = function () {
            private_method();
        }
    }

[ 本帖最后由 典 于 2012-1-9 14:34 编辑 ]
Advertisement
Advertisement

发表于 2012-1-11 11:35 |显示全部楼层
此文章由 o2h2o 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 o2h2o 所有!转贴必须注明作者、出处和本声明,并保持内容完整
google closure tools
和 yui 都有类似的功能
去掉comment,去掉空格,minifiy
还可以把长变量名自动变成短变量名

看了一下
这个好像不太一样
可以执行做test

[ 本帖最后由 o2h2o 于 2012-1-11 11:37 编辑 ]

发表回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Advertisement
Advertisement
返回顶部