gpt4 book ai didi

javascript - 如何记录闭包

转载 作者:行者123 更新时间:2023-11-29 10:48:18 24 4
gpt4 key购买 nike

我正在尝试在一个名为 User 的类中记录功能,该类位于一个闭包内 - 我如何使用 JsDoc3 来做到这一点?

这是我所拥有的:

/**
@class User
@classdesc This is the class that describes each user.
*/
(function($){

var _defaults = {
'first_name': '',
'last_name': ''
};

/**
@constructor
*/
function User(options) {
this.options = $.extend({}, _defaults, options);
}

/**
@method
@desc Returns the combined first name and last name as a string
@returns {string}
*/
User.prototype.getName() = function(){
return this.options.first_name + this.options.last_name;
};

window.User = User;

}(jQuery));

最佳答案

我用这个方法成功了。 (添加到样板插件中,因此包含 MIT 许可证注释)

请参阅@global + @class 的使用以及原型(prototype)上的@global。这似乎可以做到。

代码复制如下:请享受并让它变得更好。

/**
* jQuery lightweight plugin boilerplate
* Original author: @ajpiano
* Further changes, comments: @addyosmani
* Licensed under the MIT license
*/

;(function ( $, window, document, undefined ) {

var pluginName = "Application",
defaults = {
propertyName: "value"
};

/**
* @global
* @class Application
* @description MASTER: Sets up and controls the application
*
* @returns Object
*/
function Application( element, options ) {
this.element = element;
this.options = $.extend( {}, defaults, options) ;
this._defaults = defaults;
this._name = pluginName;
this.init();
window[pluginName] = this;
}

/** @global */
Application.prototype = {

/**
* @description call pre-life initialisations and tests here
*/
init: function() {

var that = this;
that._build();
that._setNotifications();
},

/**
@description Set up a pub sub for global notifications such a state-changes.
*/
_setNotifications: function(el, options) {
console.log('Application=>setNotifications()');
},


/**
@description All environment setup done we now call other plugins.
*/
_build: function(el, options) {
console.log('Application=>build()');
}
};

$.fn[pluginName] = function ( options ) {
return this.each(function () {
if (!$.data(this, "plugin_" + pluginName)) {
$.data(this, "plugin_" + pluginName,
new Application( this, options ));
}
});
};




})( jQuery, window, document );

关于javascript - 如何记录闭包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15145782/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com