Question

I've got a base view method for my application that has a close method. It works great up until the point where I have to document it; basically I'm putting in a needless function call in order to properly document it. As Backbone already has an initialize function, it makes no sense to call it again here, taking up lines of code.. but if I drop this function from the code then the documentation for the view isn't generated. My code looks like this:

/**
 * @exports BaseView
 */
define(['backbone'], function( Backbone ) {
    'use strict';
    return Backbone.View.extend( /** @lends BaseView.prototype */ {
        /**
         * Base view with close method
         * @exports BaseView
         * @augments Backbone.View
         * @constructor
         */
        initialize: function() {
            Backbone.View.prototype.initialize.call(this);
        },
        /**
         * Removes the view from the DOM and unbinds all events.
         */
        close: function() {
            this.remove();
            this.unbind();
            if (this.onClose) {
                // Optionally, run additional cleanup methods.
                this.onClose();
            }
        }
    });
});

This question got me on the right track with documenting, but now I'd like to know if it's possible in JSDoc to document that the initialize method is inherited from Backbone.View instead of writing the function call.

Would be grateful if anyone can point me in the right direction. Thanks.

Was it helpful?

Solution

Does the following do what you want? I've just removed the initialize function, added @name BaseView to the doclet that was in front of it and removed the @exports ... that was in the same doclet because it seemed incorrect there.

/**
 * @exports BaseView
 */
define(['backbone'], function( Backbone ) {
    'use strict';
    return Backbone.View.extend( /** @lends BaseView.prototype */ {
        /**
         * Base view with close method
         * @augments Backbone.View
         * @constructor
         * @name BaseView
         */

        /**
         * Removes the view from the DOM and unbinds all events.
         */
        close: function() {
            this.remove();
            this.unbind();
            if (this.onClose) {
                // Optionally, run additional cleanup methods.
                this.onClose();
            }
        }
    });
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top