Skip to content

callable classes #283

@nyuichi

Description

@nyuichi

According to @yosuke-furukawa san, something like python's __call__ method (that's for objects, and in this case for classes) will be useful if introduced.

Many nodejs modules (ex. https://github.com/flatiron/nock) are providing a kind of tricky API, that is a function object which returns new instances every time it's called. They are alternative style of class and JSX doesn't have a means of getting access to these functions.
I suggest JSX introduce a special method called __new__, which enables users to call classes directly as if it is an object.

var nock = require('nock');

// creating a nock object via function call, not `new` operation
var couchdb = nock('http://myapp.iriscouch.com');
// A class that has a `__new__` method can called as if an object
native class nock {
    static function __new__ (url : string) : scope;
} = "require('nock')";

class _Main {
    static function main (args : string[]) : void {
        var scope = nock();
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions