【发布时间】:2009-08-11 21:42:20
【问题描述】:
我想问一下我下面的 OOP 风格的优缺点。 我以以下方式编写我的 JS 类。
var MyClass = function() {
// private vars
var self = this,
_foo = 1,
_bar = "test";
// public vars
this.cool = true;
// private methods
var initialize = function(a, b) {
// initialize everything
};
var doSomething = function() {
var test = 34;
_foo = cool;
};
// public methods
this.startRequest = function() {
};
// call the constructor
initialize.apply(this, arguments);
};
var instance_1 = new MyClass();
var instance_2 = new MyClass("just", "testing");
这是一个好方法吗?有什么缺点吗? 我不使用继承,但是这样可以实现继承吗?
提前致谢。
【问题讨论】:
标签: javascript oop