Kan ik toegang tot de "class object" van binnen de klasse lichaam in typoscript

stemmen
2

Kan ik iets wat lijkt op CoffeeScript of Ruby waar ik klasse- Macro's kan creëren doen

class A
    # events adds the class method listenTo to the class (not to the prototype)
    # listenTo will make all instances of A a listener to the given Event
    events @

    # this will register instances of A to listen for SomeEvents
    # the event broker (not here in this code) will specifically look
    # for a method called onSomeEvent(event)
    @listenTo SomeEvent

    # and then later
    onSomeEvent: (event)-> #do what ever is needed

Dit zal de volgende JavaScript-code maken

var A;
A = (function() {
   function A() {}
   events(A);
   A.listenTo(SomeEvent);
   A.prototype.onSomeEvent = function(event) {};
   return A;
})();
De vraag is gesteld op 02/10/2012 om 08:41
bron van user
In andere talen...                            


1 antwoorden

stemmen
2

Kijkend naar je bijvoorbeeld als je dit te schrijven:

function events(A:any) {
    A.listenTo = function(arg:any){alert(arg);};
}

class A {
    public onSomeEvent(event:any) {
        //do stuff  
    }
    constructor {
        events(A);
        (<any>A).listenTo("SomeEvent");
    }
}

schrijfmachine, zal het samenbrengen in:

function events(A) {
    A.listenTo = function (arg) {
        alert(arg);
    };
}
var A = (function () {
    function A() {
        events(A);
        (A).listenTo("SomeEvent");
    }
    A.prototype.onSomeEvent = function (event) {
    };
    return A;
})();
antwoordde op 03/10/2012 om 23:43
bron van user

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more