0
JSDoc註釋是否足以測試參數的有效性?Closure Compiler JsDoc註釋替換源代碼中的測試?
例如:在下面的「add」方法中,參數(Point對象)定義爲非空值點類型。在此方法中,用關閉編譯器,可以予然後跳到測試此參數的值所需的代碼:
if (!point) {...
if (!(point instanceof Point)) {...
由於
class Point{
/**
* Add x/y values to the Point object
*
* @param {!Point} point The x/y values to add.
*
*/
add(point) {
this.x += point.x;
this.y += point.y;
}
}