jsdoc toolkit使用在anonymous function寫法

tag:

@name  當無法辨識類型時,使用此tag直接定義名稱。(範例如下)

//利用字串建立一個function
eval("window.test= function() {};")

@lends 幫助function去參照其他class和object。

example:

/*

  • @name View
  • @class
  • @constructor
    /
    (function(){
    /*
  • @lends View
    */
    function View(){

    var _name;
    
    /**
    * @param {String} name
    */
    this.setName = function(name){
            _name = name;
    };
    

    }

/**

  • @param {string} str
    */
    View.prototype.show = function(str){
    alert("show:"+str);
    
    }

})();

直接定義一個View,並將type設成class,再由內部的lends tag去參照之前所定義的名稱。  

下圖為產生的文件: jsDoc toolkit document

Jsdoc toolkit Introduction

jsdoc toolkit是一個能夠將javascript註解產成文件的工具。 tag的寫法和download可以參考相關資訊。 以下是一個簡單的example:

/**
* @author Sparrow
*/

/**
* @class Dog is an animal.
* @constructor
*/
function Dog(){

    var _name;

    /**
    * @description Set the dog name.
    * @param {string} name
    */
    this.setName = function(name){
        _name = name;
    }

    /**
    * @description Get the dog name.
    * @type String
    */
    this.getName = function(){
        return _name;
    }

}

/**
* @description Attack a target.
* @param {String} target
*/
Dog.prototype.attack = function(target){
    alert("attack:"+target);
}

最後只要在terminal執行以下指令: java -jar jsrun.jar app/run.js Dog.js -t=templates/jsdoc/