CNode

传统面向对象 的 JS 模块 - ZNOW, 求意见

分享
IIcarusSO发布于12 年前最后回复12 年前4 回复3580 浏览0 收藏

大家好, 虽然一直在cnnode 的帖子学习, 还是等到今天才注册 ...

尝试写了个 class-based 的 js framework, 希望各位大大能给一些意见. http://icarusso.github.io/ZNOW

此framework 是编程web applications 时开发的, 希望能简易在 javascript 运用传统的oo 技巧, 包括不同的oo design patterns. 他的extends & implements 拥有checking & validating 功能, 希望能增加编码的可读及维护性. (尤其当负责编程的团队不是太熟悉javascript)

有较完整的传统面向对象功能, 例如 interface, abstract, 及不同程度的 encapsulation, 包括 private, protected, public. 其他功能包括 static, const. 另外, class 亦原生 observer-pattern, 简化编程

编程的代码例子如下

var ClassA=Class({
	init:function(a){
		this._a=a;
	},
	foo:function(){
		return this._a;
	},
	_a:false
})

var ClassB=Class.extends(ClassA)({
	init:function(a,b){
		this.super(a);
		this._b=b;
	},
	foo2:function(){
		return this.foo()+this._b;
	},
	_b:false
})

var b=new ClassB('a','b');
b._b; //禁止
console.log(b.foo2()); //ab

第一次分享的框架, 希望各位大大能给些意见.

查看回复

回复 (4)

I
IcarusSO#1·12 年前

下载及介绍网站: http://icarusso.github.io/ZNOW

L
leapon#2·12 年前
I
IcarusSO#3·12 年前

其中最大不同在于 encapsulation 在 ZNOW, 拥有 private & protected 特性, private data 不会被 access

例如

var ClassA=Class({
	init:function(a){
		this._a=a;
	},
	foo:function(){
		return this._a;
	},
	_a:false
})

var a=new ClassA('a');
console.log(a._a == 'a'); //false
console.log(a.foo() == 'a'); //true
I
IcarusSO#4·12 年前

另外, 我认为Classical Inheritance in JavaScript 提及的type convenient 及code reuse, 属于strong type programming vs weak type programming. ZNOW 建于javascript, weak type programming 的特性, 包括type convenient & code reuse 亦会保留. 当然,在 instance 新增或删除 methods 会影响 可读及维护性. 这是另一個 topic, 但 ZNOW 是支援的.

参与回复
登录后即可参与回复。登录