Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function(){
- console.log('Hello. Step 1. The simplest possible variant. A function calls another function - event listener.');
- // I will be creating events
- // 1) Only 1 class. The function trigger and the event listener are in the same class.
- // Everyhtign is hard coded listeners can not be called at runtime in C# for example in JS we will not have problems.
- // Even in C# we can inherit and override the function "onExecuteSomething"
- function A()
- {
- this.executeSomething = function(){ // the trigger
- console.log('I have to execute something and call the event listener afterwords');
- this.onExecuteSomething();
- // if you want to trigger another listener you have to add extra code here
- // ... this.anotherOnExecuteSomethign
- };
- // In the very same class I can define an event listener
- // Event listener
- this.onExecuteSomething = function(){ // the listener
- console.log('I have been called by executeSomething/foo/bar/bas');
- }
- }
- // Instantiate an object call the method(s)
- var a = new A();
- a.executeSomething();
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement