关于如何创建javascript类的建议

关于如何创建javascript类的建议,javascript,class,jquery,Javascript,Class,Jquery,我有一个采用这种架构的Java应用程序:实体+持久性+业务+REST服务 我想创建没有JSF的视图层,换句话说,我只想使用HTML+CSS+JS(JQuery+Ajax) 创建JavaScript类以访问REST服务的更好方法是什么 var Bookmark = function() { this.id; this.description; this.link; }; Bookmark.prototype._insert = function() { // here should i put

我有一个采用这种架构的Java应用程序:实体+持久性+业务+REST服务

我想创建没有JSF的视图层,换句话说,我只想使用HTML+CSS+JS(JQuery+Ajax)

创建JavaScript类以访问REST服务的更好方法是什么

var Bookmark = function() {
this.id;
this.description;
this.link;
};

Bookmark.prototype._insert = function() {
// here should i put the JQuery Ajax Call?
}; 

Bookmark.prototype._delete = function() {
// here should i put the JQuery Ajax Call?
}

Bookmark.prototype._update = function() {
// here should i put the JQuery Ajax Call?
}

Bookmark.prototype._findById = function() {
// here should i put the JQuery Ajax Call?
}

Bookmark.prototype._findById = function() {
// here should i put the JQuery Ajax Call?
}

以上格式可以接受吗?

您所拥有的是可以接受的。您可能会遇到的问题是,如果您与服务器的交互没有明确地落入一个模型对象的领域,那么您的模型层将变得混乱

为什么不像在服务器上那样创建一个服务层呢

App.API =  {

     login: function(onSuccess) {....}

     findBook: function(id, onSuccess) {....}


}

我会说对你有用的。angular.js已经为使用AJAX的服务提供了支持。