我应该如何使用JSDoc在我的设计模式中记录DOM事件?

时间:2016-08-29 21:19:18

标签: javascript jquery jsdoc jsdoc3

我有一个定制的JavaScript框架,我从在我之前工作的人那里继承。我可以说它是一个利用jQuery的各种Web应用程序。

有很多事件被我要记录的各种对象触发,但我不确定如何做到这一点。我见过JSDoc 3's examples on the @listens page,但它们似乎更倾向于模块开发模式,所以我不确定如何将它们应用于模式:

ClassA.js:

var ClassA = function (args) {
    //constructor stuff goes here... usually punctuated with:
    this.listenForEvents();
};

ClassA.prototype.listenForEvents = function () {
    $(document).on("someEvent", function (e, args) {
        //Event handlers are almost always anonymous and call class methods,
        //usually to determine if the event needs to be handled by a specific
        //instance of the class, or meeting a criteria. e.g.:
        if (this.identifier === args.identifier) {
            this.someClassMethod(args);
        }
    }.bind(this));
};

ClassA.prototype.someClassMethod = function (args) {
    //handle the event
};

ClassB.js:

var ClassB = function (args) {
    //constructor stuff goes here...
};

ClassB.prototype.doAThing = function () {
    //code goes here
    $(document).trigger('someEvent', { identifier: 'someIdentifier', aValue: 1, anotherValue: 'two' });
};

我在这种设计模式中如何/在何处使用@event@listens@fires doclet?

0 个答案:

没有答案