You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I guess replacing the object literal with an anonymous function would do the job.
Maybe have transcrypt compile to this:
var A = __class__ ('A', [B], (function(){
let o = {};
o.__module__ = __name__;
o.X = 1;
o.Y = o.X + 2;
return o;
})());
but that would also make getters more verbose. Example with method that returns self.X:
(EDIT: This is not working, the new property is not picked up by for-in loops)
var A = __class__ ('A', [B], (function(){
let o = {};
o.__module__ = __name__;
Object.defineProperty(o, 'someFunctionName', { get: function() { return __get__ (this, function (self) {
return self.X;
});}});
return o;
})());
//...
export var B = __class__ ('B', [object], function(){
let cls = {};
cls.__module__ = __name__,
return cls;
}());
export var A = __class__ ('A', [B], function(){
let cls = {};
cls.__module__ = __name__;
cls.X = 1;
cls.Y = cls.X + 2;
__def_method__(cls, function test(self){
return self.X;
});
return cls;
}());
Performance for class declaration, object instantiation and method calls are the same, the memory profile seems to be the same. It also allows method redefinition of instances.
Activity
AlexECX commentedon May 8, 2019
I guess replacing the object literal with an anonymous function would do the job.
Maybe have transcrypt compile to this:
but that would also make getters more verbose. Example with method that returns self.X:
(EDIT: This is not working, the new property is not picked up by for-in loops)
AlexECX commentedon May 10, 2019
This seems to be working pretty well. Haven't looked into the python transpile code yet, might give it a try sometime.
Example.py
transcrypt.org js
Example.js
Performance for class declaration, object instantiation and method calls are the same, the memory profile seems to be the same. It also allows method redefinition of instances.
some more in-depth testing
AlexECX commentedon May 11, 2019
A simpler, closer to current transcrypt and probably easier to implement version:
transcrypt.org js
Examplse.js