call empty function in class

Topics: General
May 10, 2013 at 4:46 PM
You can write following:
declare class A {
    function():any;
}
But you cannot call this function:
var x = new A();
x();
Value of 'A' is not callable.

How the function can be called ?
If it cannot be called why this is allowed ?
Coordinator
May 10, 2013 at 5:36 PM
The declare keyword is used to describe existing objects. If you try to describing an existing object that doesn't actually exist, you will get an error.

If you want to write an actual class, don't use declare:
class A {
    public fn() { }
}
May 10, 2013 at 6:19 PM
You don't really need existing object.
This is valid code:
declare class A {
    f():any;
}

var x = new A();
x.f();
The question is what "function():any" means in declared class and why it is allowed.
Coordinator
May 10, 2013 at 8:46 PM
Sorry, I misinterpreted the post. What this does is create a function called 'function':
declare class A {
    function():any;
}

var x: A;
x.function();
May 10, 2013 at 8:48 PM
Ah.. right :)
Thanks