Skip to content

Commit

Permalink
#161 Replace Hand-Made JS OO Code with default ES-Syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
mirkosertic committed Jun 21, 2019
1 parent d090c02 commit 448d452
Showing 1 changed file with 67 additions and 19 deletions.
86 changes: 67 additions & 19 deletions core/src/test/resources/classtest.html
Original file line number Diff line number Diff line change
@@ -1,54 +1,102 @@
<html>
<body>
<script>
var InitProxyHandler = function() {
var C = function(selfRef) {
this.selfRef = selfRef;
this.initialized = false;
};
C.prototype.construct = function() {
if (!this.initialized) {
this.initialized = true;
this.selfRef.initialize();
}
return new this.selfRef();
};
C.prototype.get = function(target, prop, receiver) {
if (!this.initialized) {
this.initialized = true;
this.selfRef.initialize();
}
return this.selfRef[prop];
};
C.prototype.set = function(obj, prop, value) {
if (!this.initialized) {
this.initialized = true;
this.selfRef.initialize();
}
this.selfRef[prop] = value;
};
return C;
}();

var jlObject = function() {

var constructor = function() {
var C = function() {
this.property1 = 'Defaultvalue1';
};
C.STATICMEMBER = 10;
C.VOIDinit = function() {
};

constructor.prototype.clone = function() {
C.prototype.constructor = C;
C.prototype.clone = function() {
return this;
};
constructor.prototype.getClass = function() {
return jlObject;
};
constructor.getName = function() {

C.getName = function() {
return 'java.lang.Object';
};

return constructor;
}();
C.initialize = function() {
console.log("Initialized " + C.getName());
};

return new Proxy(C, new InitProxyHandler(C));
}();

var jlMath = function() {
var constructor = function() {
var C = function() {
jlObject.prototype.constructor.call(this);
this.property2 = 'Defaultvalue2';
};
C.VOIDinit = function() {
jlObject.VOIDinit.call(this);
};

constructor.prototype = Object.create(jlObject.prototype);
constructor.prototype.constructor = constructor;
constructor.prototype.add = function(a, b) {
C.prototype = Object.create(jlObject.prototype);
C.prototype.constructor = C;
C.prototype.add = function(a, b) {
return a + b;
};
constructor.prototype.getClass = function() {
return jlMath;

C.getName = function() {
return 'java.lang.Math';
};
constructor.getName = function() {
return "java.lang.Math";

C.initialize = function() {
console.log("Initialized " + C.getName());
};

return constructor;
return new Proxy(C, new InitProxyHandler(C));
}();

var obj = new jlObject();
jlObject.VOIDinit.call(obj);
console.log(jlObject.STATICMEMBER);
jlObject.STATICMEMBER = 33;
console.log(jlObject.STATICMEMBER);

var math = new jlMath();
var cl = math.clone();

console.log(obj);
console.log(math);
console.log(cl);
console.log(math.add(10,20));
console.log(obj.getClass().getName());
console.log(math.getClass().getName());
console.log(obj.constructor.getName());
console.log(math.constructor.getName());
console.log(math);
</script>
</body>
</html>

0 comments on commit 448d452

Please sign in to comment.