【发布时间】:2009-10-03 00:37:16
【问题描述】:
我在层次结构中有多个对象,它们具有从超类继承的公共属性和方法,以及子类中特定于对象的属性和方法。我还是 OOP javascript 的新手,所以可能有更好的方法。我将 jQuery 用于 AJAX,但不确定这是否有任何区别。
function Obj(input) {
this.in = input;
this.out = {
content: this.in,
category: {},
owner: utils.getValidUser(),
state: 0,
meta: {}
};
this.process = function() {
console.log("No Process Defined");
}
}
function MovieObj(input) {
this.inheritFrom = Obj;
this.inheritFrom();
this.out.type = "movie";
}
function ActionMovie(input) {
this.inheritFrom = MovieObj;
this.inheritFrom();
this.out.genre = "action";
this.process = function() {
console.log("movie search");
$.getJSON("/api/search/"+ escape(this.out.content),
function(data) {
/*
I want to modify the object properties according to
what comes back from the ajax call.
*/
});
}
}
【问题讨论】:
标签: javascript ajax inheritance oop