Open pitust opened 4 years ago
FYI: LiveScript classes look like the following:
class A
-> console.log \hello
x: (y) -> 2 * y
t: ~> 2 * t
...and compiles to the following Javascript:
var A;
A = (function(){
A.displayName = 'A';
var prototype = A.prototype, constructor = A;
function A(){
this.t = bind$(this, 't', prototype);
console.log('hello');
}
A.prototype.x = function(y){
return 2 * y;
};
A.prototype.t = function(){
return 2 * t;
};
return A;
}());
function bind$(obj, key, target){
return function(){ return (target || obj)[key].apply(obj, arguments) };
}
if we get prototype
working, then we can use TS->ES3 transpilation to have classes as well.
I don't want to make a separate implementation for classes for now.
Let's cover ES3 first, this will open many doors :)
What if we made Functions be Objects?
(that would let us have the first thing @eclipticccc suggested)
Here is how i see it: make functions have an internal field, lets say __internal_fnptr_call
, and when we call them, use that field instead.
@pitust it already kind of works like that
there are actually 3 things:
Maybe, but code like:
function f() {}
f.a = 3;
doesn't work. However, this does work:
function __real_f() {}
var f = {};
f.__internal_fnptr_call = __real_f;
f.a = 3;
ah I see. there's a difference between this
(i.e. instance of a function) and statically adding fields to the function object. yes that is still not implemented.
Classes shouldn't be too difficult to get working, especially in typescript, and should be even easier than prototypes (i think).