私は現時点でJavascriptの継承にいくつかの異なるアプローチを試みています。Javascript継承
(http://www.kevlindev.com/tutorials/javascript/inheritance/index.htmから '借り')
今KV = {};
KV.extend = function(subClass, baseClass) {
function inheritance() {}
inheritance.prototype = baseClass.prototype;
subClass.prototype = new inheritance();
subClass.prototype.constructor = subClass;
subClass.baseConstructor = baseClass;
subClass.superClass = baseClass.prototype;
}
function GridView() {
var _ownerElement;
}
GridView.prototype.getOwnerElement = function() {
return this._ownerElement;
}
GridView.prototype.setOwnerElement = function(ownerElement) {
this._ownerElement = ownerElement;
}
GridView.prototype.initialize = function() {
this.setOwnerElement('test');
}
function StreetGridView(dataURL, ownerElement) {
StreetGridView.baseConstructor.call(this);
StreetGridView.superClass.initialize();
StreetGridView.superClass.setOwnerElement(ownerElement);
}
// subclass StreetGridView
KV.extend(StreetGridView, GridView);
、私はStreetGridViewのインスタンスを作成するとき、私は何の問題それにGETOWNERELEMENT()を呼び出すことはできません:私は、次のコードを持っています。すべてが期待どおりに機能します。
もつとも
Iの別のインスタンスを作成すると、インスタンス2に加えられた変更は、私は、これが共有インスタンス情報としてプロトタイプを使用しての主な問題である知っているバックインスタンス1.
を反映しています。私は今朝頭を悩ませていましたが、正しい方向に私を向けることができる人がいるかどうか疑問に思っていました!
おかげ
:http://stackoverflow.com/a/12816953/885464 jQueryのAJAXを使用して –