Skip to content

Latest commit

 

History

History
52 lines (32 loc) · 1.43 KB

README.md

File metadata and controls

52 lines (32 loc) · 1.43 KB

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: