Skip to content

Instantly share code, notes, and snippets.

View Sudharshaun's full-sized avatar
🎯
Focusing

Sudharshaun Sudharshaun

🎯
Focusing
  • PayPal
  • Chennai
  • 21:49 (UTC +05:30)
View GitHub Profile
@straker
straker / two-way-binding.js
Last active October 14, 2024 19:31
Simple and small two-way data binding between DOM and data
/**
* @param {object} scope - Object that all bound data will be attached to.
*/
function twoWayBind(scope) {
// a list of all bindings used in the DOM
// @example
// { 'person.name': [<input type="text" data-bind="person.name"/>] }
var bindings = {};
// each bindings old value to be compared for changes
@straker
straker / wrapper.js
Last active October 20, 2022 11:31
Simple wrapper around DOM functions to make DOM interactions a bit easier to work with
(function(Node, Element, HTMLCollection, Array) {
/**
* Wrap addEventListener to handle multiple event types and be chainable.
* @param {string} types - Space-separated event types.
* @param {function} listener
* @param {boolean} useCapture
* @returns {Node}
*
* @example
* document.querySelector('a')