This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // a basic delegated EventListener | |
| class DelegatedListener { | |
| constructor(delegated) { | |
| this.delegated = delegated; | |
| } | |
| handleEvent(event) { | |
| this.delegated['on' + event.type](event); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // it's so simple to have any handler you need | |
| class Clicker extends Handler { | |
| onclick(event) { | |
| alert(event.type); // click | |
| } | |
| } | |
| // generic event handler | |
| class Handler { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class TenClicks { | |
| constructor(currentTarget) { | |
| this.clicks = 10; | |
| currentTarget.addEventListener('click', this); | |
| } | |
| handleEvent(event) { | |
| this['on' + event.type](event); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // interface | |
| var EventListener = { | |
| handleEvent(e) { | |
| this['on' + e.type](e); | |
| } | |
| }; | |
| // component | |
| var Clicker = Object.create(EventListener, { | |
| clicks: {writable: true, value: 0}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var obj = { | |
| handleEvent(e) { | |
| // always true | |
| console.log(this === obj); | |
| } | |
| }; | |
| document.body.addEventListener('click', obj); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function whatAWaste(event) { | |
| // BODY, HTML | |
| console.log(event.currentTarget.nodeName); | |
| // it is ALWAYS true !!! | |
| console.assert(event.currentTarget === this); | |
| } | |
| document.documentElement.addEventListener('click', whatAWaste); | |
| document.body.addEventListener('click', whatAWaste); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Players | |
| class ClickCounter { | |
| constructor() { this.clicks = 0; } | |
| onclick(e) { this.clicks += (e.type === 'click') ? 1 : -1; } | |
| } | |
| class Handler extends ClickCounter { | |
| constructor(currentTarget) { | |
| super(); | |
| currentTarget.addEventListener('click', this); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # @example | |
| # chmod a+x randommac.sh | |
| # ./randommac.sh wlp2s0 | |
| # @credits original macOS / osX version via @rem | |
| # https://remysharp.com/2017/05/29/getting-free-wifi | |
| if [ "$1" != "" ]; then |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "use strict"; | |
| class Foo { | |
| constructor(root) { | |
| this.render = hyperHTML.bind(root); | |
| this.state = Introspected({}, $ctrl => this.update($ctrl)); | |
| this.state.items = [ | |
| { id: 1, text: "foo" }, | |
| { id: 2, text: "bar" }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // https://webreflection.medium.com/using-the-input-datetime-local-9503e7efdce | |
| Date.prototype.toDatetimeLocal = | |
| function toDatetimeLocal() { | |
| var | |
| date = this, | |
| ten = function (i) { | |
| return (i < 10 ? '0' : '') + i; | |
| }, | |
| YYYY = date.getFullYear(), | |
| MM = ten(date.getMonth() + 1), |