这个无比像Java语言:
'package jui'
.j(function() {
'import j.unit.Observable'.j();
'class Component'
.j({
constructor:function() {
},
show:function() {
console.log("Component");
}
});
'class Container extends Component implements Observable'
.j(function(jsuper, ob) {
return {
jstatic:{
a:1
},
constructor:function() {
var jthis = this;
jsuper.constructor.call(this);
ob.constructor.call(this);
console.dir(jthis.constructor.a);
}
}
});
});
实现代码:
String.prototype.j = function() {
var code;
if (arguments.length == 1) {
code = arguments[0];
return j(this.toString(), code);
}
return j(this.toString());
};
更完整代码:
本文介绍了一种模仿Java语法风格的JavaScript封装方式,通过字符串原型扩展实现了类定义及继承。示例代码展示了组件类及其子类容器的具体实现过程。
305

被折叠的 条评论
为什么被折叠?



