使用jsdoc时出现一些问题

发布于 2024-11-16 13:37:59 字数 2672 浏览 4 评论 0原文

'use strict';
/**
* ImagePreloader is a tool for multi-images preloading
*
* @example
* new ImagePreloader(['http://image1.jpg', 'http://image2.jpg'], function (oImage, this.aImages, this.nProcessed, this.nLoaded) {
*   //use jQuery
*   $('<img>').attr('src', oImage.src);
* });
*
* @author nhnst Liuming
* @version 20110623.4
* @constructor
* @param {String[]} images A collection of images url for preloading
* @param {Function} callback(oImage, this.aImages, this.nProcessed, this.nLoaded) A function to call once the every image request finishes
*/
function ImagePreloader(images, callback) {
    this.callback = callback;

    this.nLoaded = 0;
    this.nProcessed = 0;
    this.aImages = [];

    this.nImages = images.length;

    for (var i = 0, len = images.length ; i < len ; i += 1) {
        this.preload(images[i], i);
    }
}
/**
* Initialization
* @private
*/
ImagePreloader.prototype.preload = function (image, index) {
    var oImage = new Image;
    oImage.nIndex = index;
    oImage.bLoaded = false;
    oImage.oImagePreloader = this;
    oImage.src = image + '?flush=' + (+new Date());

    this.aImages.push(oImage);

    // handle ie cache
    if (oImage.width > 0) {
        this.onload.call(oImage);
    }
    else {
        oImage.onload = this.onload;
        oImage.onerror = this.onerror;
        oImage.onabort = this.onabort;
    }
};
/**
* A inner function to be called when every image request finishes
* @private
*/
ImagePreloader.prototype.onComplete = function (oImage) {
    this.nProcessed++;
    this.callback(oImage, this.aImages, this.nProcessed, this.nLoaded);
};
/**
* A inner function to be called when image loads successful
* @private
*/
ImagePreloader.prototype.onload = function () {
    this.bLoaded = true;
    this.oImagePreloader.nLoaded++;
    this.oImagePreloader.onComplete(this);
};
/**
* A inner function to be called when an error occurs loading the image
* @private
*/
ImagePreloader.prototype.onerror = function () {
    this.bError = true;
    this.oImagePreloader.onComplete(this);
};
/**
* A inner function to be called when image loading is aborted
* @private
*/
ImagePreloader.prototype.onabort = function () {
    this.bAbort = true;
    this.oImagePreloader.onComplete(this);
};

当我使用jsdoc生成doc文件时,出现一些警告,

>> WARNING: Trying to document ImagePreloader#onload without first documenting I
magePreloader.
>> WARNING: Trying to document ImagePreloader#onerror without first documenting
ImagePreloader.
>> WARNING: Trying to document ImagePreloader#onabort without first documenting
ImagePreloader.
3 warnings.

为什么?

'use strict';
/**
* ImagePreloader is a tool for multi-images preloading
*
* @example
* new ImagePreloader(['http://image1.jpg', 'http://image2.jpg'], function (oImage, this.aImages, this.nProcessed, this.nLoaded) {
*   //use jQuery
*   $('<img>').attr('src', oImage.src);
* });
*
* @author nhnst Liuming
* @version 20110623.4
* @constructor
* @param {String[]} images A collection of images url for preloading
* @param {Function} callback(oImage, this.aImages, this.nProcessed, this.nLoaded) A function to call once the every image request finishes
*/
function ImagePreloader(images, callback) {
    this.callback = callback;

    this.nLoaded = 0;
    this.nProcessed = 0;
    this.aImages = [];

    this.nImages = images.length;

    for (var i = 0, len = images.length ; i < len ; i += 1) {
        this.preload(images[i], i);
    }
}
/**
* Initialization
* @private
*/
ImagePreloader.prototype.preload = function (image, index) {
    var oImage = new Image;
    oImage.nIndex = index;
    oImage.bLoaded = false;
    oImage.oImagePreloader = this;
    oImage.src = image + '?flush=' + (+new Date());

    this.aImages.push(oImage);

    // handle ie cache
    if (oImage.width > 0) {
        this.onload.call(oImage);
    }
    else {
        oImage.onload = this.onload;
        oImage.onerror = this.onerror;
        oImage.onabort = this.onabort;
    }
};
/**
* A inner function to be called when every image request finishes
* @private
*/
ImagePreloader.prototype.onComplete = function (oImage) {
    this.nProcessed++;
    this.callback(oImage, this.aImages, this.nProcessed, this.nLoaded);
};
/**
* A inner function to be called when image loads successful
* @private
*/
ImagePreloader.prototype.onload = function () {
    this.bLoaded = true;
    this.oImagePreloader.nLoaded++;
    this.oImagePreloader.onComplete(this);
};
/**
* A inner function to be called when an error occurs loading the image
* @private
*/
ImagePreloader.prototype.onerror = function () {
    this.bError = true;
    this.oImagePreloader.onComplete(this);
};
/**
* A inner function to be called when image loading is aborted
* @private
*/
ImagePreloader.prototype.onabort = function () {
    this.bAbort = true;
    this.oImagePreloader.onComplete(this);
};

when I generate doc file using jsdoc, some warnnings occur

>> WARNING: Trying to document ImagePreloader#onload without first documenting I
magePreloader.
>> WARNING: Trying to document ImagePreloader#onerror without first documenting
ImagePreloader.
>> WARNING: Trying to document ImagePreloader#onabort without first documenting
ImagePreloader.
3 warnings.

why?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

厌倦 2024-11-23 13:37:59

我建议将 @name 和 @class 添加到 ImagePreloader:

'use strict';
/**
* @class ImagePreloader is a tool for multi-images preloading
* @name ImagePreloader
*
* @example
* new ImagePreloader(['http://image1.jpg', 'http://image2.jpg'], function (oImage, this.aImages, this.nProcessed, this.nLoaded) {
*   //use jQuery
*   $('<img>').attr('src', oImage.src);
* });
*
* @author nhnst Liuming
* @version 20110623.4
* @constructor
* @param {String[]} images A collection of images url for preloading
* @param {Function} callback(oImage, this.aImages, this.nProcessed, this.nLoaded) A function to call once the every image request finishes
*/
function ImagePreloader(images, callback) {
    this.callback = callback;

    this.nLoaded = 0;
    this.nProcessed = 0;
    this.aImages = [];

    this.nImages = images.length;

    for (var i = 0, len = images.length ; i < len ; i += 1) {
        this.preload(images[i], i);
    }
}

I would suggest adding @name and @class to ImagePreloader:

'use strict';
/**
* @class ImagePreloader is a tool for multi-images preloading
* @name ImagePreloader
*
* @example
* new ImagePreloader(['http://image1.jpg', 'http://image2.jpg'], function (oImage, this.aImages, this.nProcessed, this.nLoaded) {
*   //use jQuery
*   $('<img>').attr('src', oImage.src);
* });
*
* @author nhnst Liuming
* @version 20110623.4
* @constructor
* @param {String[]} images A collection of images url for preloading
* @param {Function} callback(oImage, this.aImages, this.nProcessed, this.nLoaded) A function to call once the every image request finishes
*/
function ImagePreloader(images, callback) {
    this.callback = callback;

    this.nLoaded = 0;
    this.nProcessed = 0;
    this.aImages = [];

    this.nImages = images.length;

    for (var i = 0, len = images.length ; i < len ; i += 1) {
        this.preload(images[i], i);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文