Skip to content

on(btn).click += handler; C# style event handling with operator overloading.

License

Notifications You must be signed in to change notification settings

FilipZawada/Fingers.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fingers.js

Fingers is a proof-of-concept micro JavaScript library. It hacks js + and - operators to provide a nice way of adding event listeners. It's not using any transcompiler, just pure JavaScript, plus a Proxy goodness from ES6 (already supported by Chrome, Firefox).

So, let's try:

var button = document.getElementById("btn");



on(button).click += handler1 + handler2;

click(); // outputs: handler1, handler2

on(button).click -= handler1;

click(); // outputs: handler2

on(button).click -= handler2;

click(); // outputs: {empty}

///// utils /////

function handler1() {
    console.log("handler1");
}
function handler2() {
    console.log("handler2");
}    
function click() {
    // simulate user click
    button.dispatchEvent(new MouseEvent("click"));
}

Do you find this interesting? Please help spread the word by tweeting #fingersJS

Links:

Author:

About

on(btn).click += handler; C# style event handling with operator overloading.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published