(function($){
'use strict';
var ezAutoSuggestion = function( selector, href ){
return new init(selector, href);
};
//construct
var init = function( selector, href ){
defaults.call(this);
//property
this.element = $(selector);
this.href = href;
this.inputText = $(selector + " input[type='text']" );
this.inputText.after(this.suggestionList);
this.list = $(selector + " ul");
this.choosen = selector + " li";
//method
this.getDatas();
this.hideList();
this.choose();
};
//method
init.prototype.getDatas = function(){
//post input keyup value and get data from backend
};
init.prototype.choose = function(){
//add user's choose into input text
};
init.prototype.hideList = function(){
//user click blank area hide auto suggestion
};
window.ezAutoSuggestion = ezAutoSuggestion;
})(jQuery);
我是编写javascript插件的新手,我写了一个简单的自动建议插件,并且我已经为github MIT许可证下载了它。
我的问题是
首先,我创建了一个construct function,
,在我的构造函数中,我设置了properties
而不是start call methods
。 (我还借用了jQuery的创意用户函数来创建new init object
,因此用户不需要输入新内容)
这是好方法吗?还是有更好的方法来构建它?
这是我的github链接 https://github.com/yben56/ez-auto-suggestion