2017-08-04 37 views
0

如何正確記錄擴展String對象原型的函數?例如:如何正確地爲修改String原型的內聯函數編寫JSDoc?

if (!String.prototype.format) { 
    /** 
    * @name String.prototype.format 
    * Replaces symbols like {0}, {1} in a string with the values from the arguments. 
    */ 
    String.prototype.format = function() { 
     var args = arguments; 
     return this.replace(/{(\d+)}/g, function (match, number) { 
      return typeof args[number] != 'undefined' 
       ? args[number] 
       : match 
      ; 
     }); 
    }; 
} 

我嘗試了使用和不使用@function和@name註釋。

它不起作用,因爲Visual Studio 2017不會像添加JSDoc註釋時那樣開始顯示帶有函數描述的工具提示。

回答

0

這是否工作

if (!String.prototype.format) { 
    /** 
    * @namespace String 
    */ 

    /** 
    * @memberof String 
    * @name String#format 
    * @function 
    * Replaces symbols like {0}, {1} in a string with the values from the arguments. 
    */ 
    String.prototype.format = function() { 
     var args = arguments; 
     return this.replace(/{(\d+)}/g, function (match, number) { 
      return typeof args[number] != 'undefined' 
       ? args[number] 
       : match 
      ; 
     }); 
    }; 
} 
+0

遺憾的是它仍然在Visual Studio 2017年沒有,但它似乎想說明它取之有道。 – K48

+0

嘗試刪除'@ name'行並將'@ function'更改爲'@function format' – lofihelsinki

+0

nope不起作用 – K48